Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

159
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda