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

230
Views
How to make the nested items of array to object?

I have a nested array like this:

var arr = [
            ['Simcard', 'one'],
            ['Charge', 'two'],
          ];

I want to make it like this:

[
   {"Simcard": "one"},
   {"Charge": "two"},
]

How can I do that?


Here is what I've tried but not exactly the expected result:

let res = Object.keys(x).map((key) => {key: x[key]});
about 4 years ago · Juan Pablo Isaza
3 answers
Answer question

0

There's a builtin Object.fromEntries that turns a two-element array into an object.

var arr = [
            ['Simcard', 'one'],
            ['Charge', 'two'],
          ];

var desired = [
   {"Simcard": "one"},
   {"Charge": "two"},
]

var answer = arr.map(entry => Object.fromEntries([entry]));

console.log(answer)

about 4 years ago · Juan Pablo Isaza Report

0

This is not a oneliner, but you could try the following

let res = []
arr.forEach(element => res[element[0]] = element[1])
about 4 years ago · Juan Pablo Isaza Report

0

let res = arr.map(item => ({[item[0]]: item[1]}))
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!