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

145
Views
get value of second data which has the same name as first data with javascript

so I have this json

items: [
  {
    id: 123
  },
  {
    id: 456
  }
]

and I am trying to get the value with javascript of the second id which has a value of 456, but I have no idea how to because it doesnt have a specified parent by which I could get it.

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

0

Your use case isn't exactly clear so the best answer I have for this is to specify the index:

const data = [
  {
    id: 123
  },
  {
    id: 456
  }
];

const secondId = data[1]?.id;

If you are looking for a specific id you can use the find method:

const data = [
  {
    id: 123
  },
  {
    id: 456
  }
];

const secondObj = data.find(a => a.id === 456);

It should also be noted that if you're hitting an API that's querying a database you can't expect that 456 will always be the second object unless the backend code is explicitly ordering it this way.

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!