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

235
Views
cómo obtener el valor con la ayuda de include/index of

cómo obtener el valor de alguna manera si la clave coincide con "Artículo"

 const data = [{ "Item-55566": "phone", }, { "Items-44555": "Case", } ]; /* How to get value if index found by Item */ for(let i = 0; i<data.length; i++) { console.log(data[i].includes("Item")); //Expecting phone and case }
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

for-in le permite recorrer las claves de un objeto. No debe confundirse con for-of , que recorre los elementos de una matriz.

 const data = [{ "Item-55566": "phone", }, { "Items-44555": "Case", } ]; for(let datum of data) { for(let key in datum) { if(key.includes("Item")) { console.log(datum[key]); } } }

about 4 years ago · Juan Pablo Isaza Report

0

Si desea mantener su bucle (bueno, es solo un bucle en comparación con otras respuestas), puede hacerlo con Object.keys y valores:

 const data = [{ "Item-55566": "phone", }, { "Items-44555": "Case", } ]; /* How to get value if index found by Item */ for(let i = 0; i<data.length; i++) { if(Object.keys(data[i])[0].includes('Item')){ console.log(Object.values(data[i])[0]); } }

about 4 years ago · Juan Pablo Isaza Report

0

De la manera simple, simplemente cambie data[i].includes("Elemento") a data[i].keys().includes("Elemento").

¡PERO! ¿Podríamos tener algún conjunto de datos alternativo aquí? Por ejemplo:

 const data = [{ "Item-55566": "phone", "SomeKey: "Some Value", 123123: "Numeric key with value" }, { "Items-44555": "Case", "Another-key": "Another value" } ];

En este caso, debe realizar algunos cambios en su código para encontrar las claves y los valores correctos:

 for(let i = 0; i<data.length; i++) { data[i].keys().forEach(v=>{ String(v).includes("Item") && console.log("Got index: ${i}, key: ${v}, value: ${data[i][v]}") }) }
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!