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

215
Views
Obtener valores de una matriz de objetos dinámicos

Hola, en Javascript obtengo un resultado de error del objeto de matriz de resultados de API que puede ser

 { ProjectName:["Invalid Project Name"], entityName:["Invalid entityName"] }

o

 { ProjectName:["Invalid Project Name"], }

y los nombres de las claves son dinámicos y provienen de la API. entonces solo necesito valores como

 ["Invalid Project Name","Invalid entityName"]

¿Cómo puedo convertir este objeto en esta matriz?

Gracias por adelantado

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

0

 var errors = []; var obj = { ProjectName: ["Invalid Project Name"], entityName: ["Invalid entityName"], }; Object.keys(obj).map((k) => { obj[k].map((x) => errors.push({ key: k, message: x, }) ); }); errors.map(k => { console.log("Check " + k.key + " field: " + k.message) })

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar el método Object.keys con reduce

 const obj = { ProjectName:["Invalid Project Name"], entityName:["Invalid entityName"] } const result = Object.keys(obj).reduce((prev, curr) => { prev.push(obj[curr][0]); return prev; }, []); console.log(result);

about 4 years ago · Juan Pablo Isaza Report

0

Puede usar Object.values combinado con map y flat:

 var obj = { ProjectName: ["Invalid Project Name"], entityName: ["Invalid entityName"], }; console.log(Object.values(obj).map(i => i).flat())

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!