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

112
Views
Encuentra el índice de un objeto en una matriz de objetos

Tengo una matriz que se ve así:

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

¿Cómo encuentro el índice del objeto con la clave "-MrUUB4PcPD5G45NGb-y" por ejemplo?

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Puede usar findIndex() y mirar Object.keys() para cada objeto en la matriz para ver si la clave que desea está en esa matriz de claves

 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!