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

142
Views
¿Cómo verificar si hay algún valor dentro de la matriz de objetos (que también es un objeto) en javascript?

Tengo este objeto en js:

 var list = { "1": { "id": "1", "start_date": "2019-01-14", "end_date": "2019-01-14", "text": "some text one", "assistent": "12" }, "2": { "id": "2", "start_date": "2021-12-01", "end_date": "2021-12-01", "text": "another text", "assistent": "15" }, "3": { "id": "3", "start_date": "2021-12-02", "end_date": "2021-12-02", "text": "one more text", "assistent": "2" } }

Quiero verificar si hay un "asistente" = 2 dentro de esta matriz de objetos y, en caso afirmativo, obtener un parámetro de "texto" para este asistente (tiene que ser "un texto más"). Lo que he probado:

 var foundtext = list.find(x => x.assistent === '2').text; console.log(foundtext);

(Mostrará que .find no es una función) También:

 var foundtext = list.find(x => x.assistent == '2')['text']; console.log(foundtext);

(mostrará el mismo error)

También probé esto:

 for (var i=1; i <= list.length; i++) { console.log(list[i]); //and than perform the search inside list[i]; }

y esto :

 list.forEach(value => { console.log(value); //and than perform the search inside value; })

Entonces, ¿cuál es el enfoque correcto para realizar este tipo de verificación?

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

0

Yo haría algo como esto.

 const text = Object.values(list).find(entry => entry.assistent === "2")?.text

EDITAR

Para la pregunta adicional en los comentarios a continuación.

 const texts = Object.values(list) .filter(entry => entry.assistent === "2") .map(entry => entry.text)
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!