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

240
Views
Cómo obtener datos de un objeto en js

Tengo un objeto y quiero obtener el nombre de usuario .

 const example = [ { id: 793, name: 'John', weight: '66', data: [ { id: 793, userName: 'John Ferny', }, ], }, ];

No estoy seguro de que example.data.filter((item) => item === item.userName sea correcto

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

0

Directamente:

 const userName = example[0].data[0].userName;

Si hay más de un nombre de usuario:

 const userNames = example.flatMap(({data}) => data.map(({userName})=> userName));

Para ENCONTRAR el primer elemento con nombre de usuario === "John Ferny"

 const item = example.filter(item => item.data.find(({userName}) => userName === user)) 

 const example = [{ id: 793, name: 'John', weight: '66', data: [ { id: 793, userName: 'John Ferny',}, ], },{ id: 794, name: 'Fred', weight: '66', data: [ { id: 794, userName: 'Fred Ferny',}, ], },]; // directly console.log(example[0].data[0].userName) // If more than one: const userNames = example.flatMap(({data}) => data.map(({userName})=> userName)) console.log(userNames) // To find an object with userName === something const user = "John Ferny" const item = example.filter(item => item.data.find(({userName}) => userName === user)) console.log(item)

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!