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

193
Views
¿Cómo accedo a una propiedad de los objetos en una matriz y la comparo?

Entonces, tengo una matriz con múltiples objetos con múltiples propiedades:

 let myArr = [{ id: 1, x: 120, y: 150, }, { id: 2, x: 170, y: 420, }, { id: 3, x: 160, y: 220, }, { id: 4, x: 140, y: 170, }];

Ahora quiero ver si la propiedad de uno de los objetos en mi matriz coincide con una variable. ¡Pero no sé cómo hacer eso! Quiero verificar si el valor de la propiedad "id" en uno de mis objetos coincide con mi variable. Algo como esto:

 if(myArr[0].id == myVar){ //do something }

pero esto para cada objeto en mi matriz

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

0

Prueba así

 let myArr = [{ id: 1, x: 120, y: 150, }, { id: 2, x: 170, y: 420, }, { id: 3, x: 160, y: 220, }, { id: 4, x: 140, y: 170, }]; let myVar = 1; const found = myArr.find(element => element.id === myVar); console.log(found)

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!