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

134
Views
Cómo mapear dos matrices en una matriz de objetos

tengo dos matrices

 keys:[key0, key1, key2, key3]

y

 body:[['jake', 24, 3, true], ['susan', 21, 0, true]]

el resultado que necesito es

 [{key0:jake, key1:24, key2:3, key3:true}, {key0:susan, key1:21, key2:0, key3:true}]
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

Asigne las claves y los valores a una matriz de pares de [key, value] y luego conviértalos en un objeto usando Object.fromEntries() (vea la función zipObject ).

Para convertir una matriz de valores, use Array.map() con zipObject :

 const zipObject = keys => values => Object.fromEntries(keys.map((key, i) => [key, values[i]])) const keys = ['key0', 'key1', 'key2', 'key3'] const values = [['jake', 24, 3, true], ['susan', 21, 0, true]] const result = values.map(zipObject(keys)) console.log(result)

about 4 years ago · Juan Pablo Isaza Report

0

const body = [['jake', 24, 3, true], ['susan', 21, 0, true]]; const keys = ['key0', 'key1', 'key2', 'key3'] let newArray = []; numbers.forEach((value) => { let obj={}; keys.forEach((key,index) => { obj[`${key}`] = value[index]; }) newArray.push(obj); }); console.log(newArray)
about 4 years ago · Juan Pablo Isaza Report

0

Esta puede ser una forma simple de hacer esto, usando bucles fáciles de leer:

 const keys = ['key0', 'key1', 'key2', 'key3']; const body = [['jake', 24, 3, true], ['susan', 21, 0, true]]; const result = []; for (let b of body) { const obj = {}; for (let i = 0; i < b.length; i++) { obj[keys[i]] = b[i]; } result.push(obj); } console.log(result);

Resultado:

 [ { key0: 'jake', key1: 24, key2: 3, key3: true }, { key0: 'susan', key1: 21, key2: 0, key3: true } ]
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!