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

161
Views
how to merge array to a multi array as key value pair
 var r = {},
 i,
    keys = ['one', 'two', 'three'],
    values = ['a', 'b', 'c'],['d', 'e',' f'];

for (let i = 0; i < keys.length; i++) {
    r[keys[i]] = values[i];
}

console.log(r);

Im just getting this error from my console. Uncaught SyntaxError: Invalid destructuring assignment target

This is the output i want to get.

{
  "one": "a",
  "two": "b",
  "three": "c"
},
{
  "one": "d",
  "two": "e",
  "three": "f"
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The main destructuring error occurs because you have an invalid values assignment, I added some square brackets around the two arrays to fix that.

let keys = ['one', 'two', 'three'],
 values = [['a', 'b', 'c'],['d', 'e',' f']];
    
let r = values.map(v => 
  Object.fromEntries(
    keys.map((k, i) => ([k, v[i]]))
  )
);

console.log(r);

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!