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
Javascript merge nested list objects

I want output like answer mentioned in the image

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

0

you can use flat for that

const data = [[{color: 1}], [{color: 2}], [{color: 3}]]

console.log(data.flat())

about 4 years ago · Juan Pablo Isaza Report

0

const list = [
  [{color1:'red',size1:21}],
  [{color2:'red',size2:21}],
  [{color3:'red',size3:21}],
  [{color4:'red',size4:21}]
]

// using built-in flat method
const ans = list.flat()
console.log(ans)

// using iterative approach (built-in map method)

const ans2 = list.map((eachArray) => eachArray[0])
console.log(ans2)


// ans1 and ans2 gives

/*

[
    {
        "color1": "red",
        "size1": 21
    },
    {
        "color2": "red",
        "size2": 21
    },
    {
        "color3": "red",
        "size3": 21
    },
    {
        "color4": "red",
        "size4": 21
    }
]

*/

Code : https://codesandbox.io/s/cocky-worker-dle269?file=/src/index.js:0-571

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!