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

115
Views
Find index of an object in an arrray of objects

I have an array that looks like this:

const arr = [ 
    { "-MrUU6N2pi7aCwJoqCzP": { "name": "test", "brand": "test", "id": 1 } }, 
    { "-MrUUB4PcPD5G45NGb-y": { "name": "test2", "brand": "test2", "id": 2 } } 
]

How do I find the index of the object with the key "-MrUUB4PcPD5G45NGb-y" for example?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

You can use findIndex() and look at the Object.keys() for each object in the array to see if the key you want is in that keys array

const arr = [ 
  {"-MrUU6N2pi7aCwJoqCzP":{"name":"test","brand":"test","id":1}}, 
  {"-MrUUB4PcPD5G45NGb-y":{"name":"test2","brand":"test2","id":2}} 
],

keyWanted = "-MrUUB4PcPD5G45NGb-y",

idx = arr.findIndex(e => Object.keys(e).includes(keyWanted))

console.log('Index =', idx)

about 4 years ago · Santiago Trujillo 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!