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

196
Views
How to make nested array into a single array in javascript

I got stuck in some problem and unable to get any idea of how to resolve it.As I have a nested array given below:

arr = [1,2,3,4,5,6,[7,8,9,[10,[21,22,[24,25,26],23],11],12,13],14,15,16,[17,18],19,20]

On using flat() method below method:

arr.flat()

it gives below output:

[1,2,3,4,5,6,7,8,9,[ 10, [ 21, 22, [Array], 23 ],11 ],12,13,14,15,16,17,18,19,20]

How can I convert this nested array into a single array.Someone let me know.

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

0

You can use the flat method here.

arr.flat(Infinity);

const arr = [
  1,
  2,
  3,
  4,
  5,
  6, [7, 8, 9, [10, [21, 22, [24, 25, 26], 23], 11], 12, 13],
  14,
  15,
  16, [17, 18],
  19,
  20,
];

const result = arr.flat(Infinity);
console.log(result);

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!