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

234
Views
How to get data from object in js

I have an object and want to get userName.

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

I'm not sure that example.data.filter((item) => item === item.userName is correct

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

0

Directly:

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

If more than one userName:

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

To FIND the first item with userName === "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!