Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

165
Visualizações
JSON array splitting React JS

I have a JSON array in my state and I want to use the other half of it. For example if the size of the JSON array is 10, I am interested in to access the later 5 values. How can I achieve that? I have tried many solutions but I always end up getting errors. I am working with React JS. So I was using map function but I am unable to fulfill my condition.

  data.map((item, index) => {

I am unable to use reduce or filter I tried that also.

about 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

As @SaeedShamloo mentioned slice method will be sufficient here

data.slice(Math.floor(data.length/2), data.length).map(item => )
about 4 years ago · Santiago Trujillo Relatório

0

Use filter by array indexes.

const data = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15];

const res = data.filter((_, idx, arr) => idx >= arr.length / 2);

console.log(res);


// Alternatively
const res2 = data.slice(-data.length/2);

console.log(res2);

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda