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

133
Vistas
What would I code if I want to extract Alex's age from this array of objects?
var students = [ {
    name:"Mary",
    age: 10
  }, 
 
  {
    name:"Barbara",
    age:11
  }, 
 
  {
    name:"David",
    age:12
  },
  
   {
    name:"Alex",
    age:11
  } ];
about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

You can use for..of syntax for iterating over the array elements. If the element has .name that you need, extract the .age:

function getAge(arr, name) {
    for (let s of students) {
        if (s.name == name) return s.age;
    }
}

Then you can use this function like this:

alert(getAge(students, 'Alex'));
about 4 years ago · Juan Pablo Isaza Denunciar

0

Use Array.find to get the item in the array whose name property is "Alex", then get the item's age property:

var students=[{name:"Mary",age:10},{name:"Barbara",age:11},{name:"David",age:12},{name:"Alex",age:11}];

let res = students.find(e => e.name == "Alex").age
console.log(res)

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