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

66
Views
Extract numbers from a n-dimensional array in javascript

Input array: [1, 2, [3, 4, [5, 6, [7, 8, [9]]]], 10]
Output array: [1,2,3,4,5,6,7,8, 9, 10]

Is there a way to get the output array without using multiple loops?

almost 4 years ago · Santiago Trujillo
2 answers
Answer question

0

You can add an infinity argument to flat to get all the numbers from the many nested arrays.

const data = [1, 2, [3, 4, [5, 6, [7, 8, [9]]]], 10];
const out = data.flat(Infinity);
console.log(out);

almost 4 years ago · Santiago Trujillo Report

0

console.log([1, 2, [3, 4, [5, 6, [7, 8, [9]]]], 10].flat(Infinity));

Use 'flat' method to flatten the array. Or you can also use underscore module method.

almost 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!