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

412
Views
javacsript array map with double [[ ]] data

I have this array:

[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]

how can i remove the first parenthesis? i tried with reduce or map but return an error:

Cannot read properties of undefined (reading 'reduce') or Cannot read properties of undefined (reading 'map').

I have to retrieve some data inside it.

Thanks for your help.

about 4 years ago · Santiago Trujillo
2 answers
Answer question

0

you can use array.flat() here

let x =[ [ { "data1": 1, "data2": 2, }, { "data1": 1, "data2": 2, } ] ]

let y = x.flat()

console.log(y) // [ { data1: 1, data2: 2 }, { data1: 1, data2: 2 } ]
about 4 years ago · Santiago Trujillo Report

0

If your data is in an array arr, there are a couple of ways:

  1. Just do arr[0].map(...) (if your data looks like in your example)
  2. Use flatMap. If there is nesting like [ [ obj1, obj2 ], [ obj3, obj4 ] ] flatMap turns it to [obj1, obj2, obj3, obj4]

Example:

arr.flatMap(_ => _)

Edit: As others have mentioned, flat works just as well. It depends whether you want to perform some operations within the flatMap also, or to get an array of only the data1 properties of the objects in your example:

arr.flatMap(el => el["data1"]) 
about 4 years ago · Santiago Trujillo 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!