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

242
Vistas
Splicing JSON object from array

I have tried splicing my json file using a for loop JSON file:

[
   {
     "name":"Billy Jean",
     "age":"52",
     "sex":"F",
     },
     {
     "name":"Bob Semple",
     "age":"32",
     "sex":"M",
     } there are more....
]

What I have tried (i imported it and called it contactList)

for(let i = 0 ; i < contactList.length ; i++){
   if(contactlist.age > 40) {
         contactList.splice(i, 1);
     }
}

if i run the code and check the output nothing changes in my JSON file

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can create a new array using Array.prototype.filter() combined with Destructuring assignment

  • Notice that age property it's of type string and should be compared as number using unary plus (+) operator

Code:

const data = [{
    "name": "Billy Jean",
    "age": "52",
    "sex": "F",
  },
  {
    "name": "Bob Semple",
    "age": "32",
    "sex": "M",
  }
]

const result = data.filter(({ age }) => +age > 40)

console.log(result)

about 4 years ago · Juan Pablo Isaza 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