Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

135
Views
mostrando el nombre de un objeto y una matriz

Tengo una matriz llamada personas, que contiene objetos y matrices dentro. Estoy tratando de mostrar todos los nombres en la matriz de hermanos. Tengo un ciclo for que muestra a John y Maria, pero cuando llamo a los hermanos, los únicos nombres que se muestran son Jenny y Jose. Probé cosas diferentes, ¿hay alguna manera de mostrar todos los nombres dentro de la matriz de hermanos?

 var persons = [{ firstName:"John", lastName:"Doe", age:50, eyeColor:"blue", weight: 180, siblings: [ {firstName:"Jenny", age:43, eyecolor:"brown",}, {firstName:"Jim", age:35, eyecolor:"green",}, {firstName:"Joe", age:29, eyecolor:"black",}, ] }, {firstName:"Maria", lastName:"Lopez", age:19, eyeColor:"brown", weight: 120, siblings: [ {firstName:"George", age:25, eyecolor:"brown",}, {firstName:"Jose", age:20, eyecolor:"green",}, ]}, ]; for(i=0; i<persons.length; i++){ console.log(persons[i].firstName); console.log(persons[i].siblings[i].firstName); }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Debe usar el método Array.forEach() para recorrer fácilmente los elementos de la matriz. Luego solo console.log el nombre.

 var persons = [{ firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue", weight: 180, siblings: [{ firstName: "Jenny", age: 43, eyecolor: "brown", }, { firstName: "Jim", age: 35, eyecolor: "green", }, { firstName: "Joe", age: 29, eyecolor: "black", }, ] }, { firstName: "Maria", lastName: "Lopez", age: 19, eyeColor: "brown", weight: 120, siblings: [{ firstName: "George", age: 25, eyecolor: "brown", }, { firstName: "Jose", age: 20, eyecolor: "green", }, ] }, ]; persons.forEach(person => console.log(person.firstName))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!