ES2019

ES2019 introduced the Array.prototype.flat() method which you could use to flatten the arrays. It is compatible with most environments, although it is only available in Node.js starting with version 11, and not at all in Internet Explorer.

const arrays = [
      ["12"],
      ["25"],
      ["22"],
      ["$10"]
    ];
const merge3 = arrays.flat(1); //The depth level specifying how deep a nested array structure should be flattened. Defaults to 1.
console.log(merge3);
    


Older browsers

For older browsers, you can use Array.prototype.concat to merge arrays:

var arrays = [
  ["12"],
  ["25"],
  ["22"],
  ["$10"]
];
var merged = [].concat.apply([], arrays);

console.log(merged);

Using the apply method of concat will just take the second parameter as an array, so the last line is identical to this:

var merged = [].concat(["$6"], ["$12"], ["$25"], ["$25"], ["$18"], ["$22"], ["$10"]);
Answer from Gumbo on Stack Overflow
🌐
W3Schools
w3schools.com › jsref › jsref_array_flat.asp
JavaScript Array flat() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › flat
Array.prototype.flat() - JavaScript - MDN Web Docs
The flat() method reads the length property of this and then accesses each property whose key is a nonnegative integer less than length. If the element is not an array, it's directly appended to the result. If the element is an array, it's flattened according to the depth parameter.
🌐
Programiz
programiz.com › javascript › library › array › flat
JavaScript Array flat() (with Examples)
// reducing nesting by flattening the array to depth 2 let flattenArray = numbers.flat(2); // new flatten array console.log(flattenArray); // Output: // [ 1, 2, 3, 4, 5, 6, [ 7, 8 ] ] ... Here, arr is an array. ... Returns a flatted array with the sub-array elements concatenated into it.
🌐
W3Schools
w3schools.io › javascript › es10-array-flatmap
ES2019(ES10) - Array FlatMap tutorials & examples - w3schools
ES10 introduced two methods to Array class to JavaScript. ... the flat method is used to return a new array with all sub-arrays concatenated recursively with a given depth Originally it was proposed as array.prototype.flatten() method.
🌐
Medium
medium.com › swlh › how-to-flatten-an-array-in-javascript-6b3fef075655
How to Flatten an Array in JavaScript | by Devin Michael Gray | The Startup | Medium
December 16, 2020 - This is slightly more efficient than using shift and unshift, as those methods would force JavaScript to re-index the array after each iteration. // non recursive flatten deep using a stack // note that depth control is hard/inefficient as we will need to tag EACH value with its own depth // also possible w/o reversing on shift/unshift, but array OPs on the end tends to be faster function flatten(input) { const stack = [...input]; const res = []; while(stack.length) { // pop value from stack const next = stack.pop(); if(Array.isArray(next)) { // push back array items, won't modify the original input stack.push(...next); } else { res.push(next); } } // reverse to restore input order return res.reverse(); }const arr = [1, 2, [3, 4, [5, 6]]]; flatten(arr); // [1, 2, 3, 4, 5, 6]
🌐
W3Schools
w3schools.com › jsref › jsref_array_flatmap.asp
JavaScript Array flatMap() Method
HTML CSS JAVASCRIPT SQL PYTHON JAVA PHP HOW TO W3.CSS C C++ C# BOOTSTRAP REACT MYSQL JQUERY EXCEL XML DJANGO NUMPY PANDAS NODEJS DSA TYPESCRIPT ANGULAR ANGULARJS GIT POSTGRESQL MONGODB ASP AI R GO KOTLIN SWIFT SASS VUE GEN AI SCIPY AWS CYBERSECURITY DATA SCIENCE INTRO TO PROGRAMMING INTRO TO HTML & CSS BASH RUST TOOLS ... Array[ ] Array( ) at() concat() constructor copyWithin() entries() every() fill() filter() find() findIndex() findLast() findLastIndex() flat() flatMap() forEach() from() includes() indexOf() isArray() join() keys() lastIndexOf() length map() of() pop() prototype push() reduce() reduceRight() rest (...) reverse() shift() slice() some() sort() splice() spread (...) toReversed() toSorted() toSpliced() toString() unshift() values() valueOf() with() JS Boolean
🌐
W3Resource
w3resource.com › javascript-exercises › javascript-array-exercise-21.php
JavaScript array: Flatten a nested array - w3resource
July 12, 2025 - JavaScript exercises, practice and solution: Write a JavaScript program to flatten a nested (any depth) array. If you pass shallow, the array will only be flattened to a single level.
Find elsewhere
🌐
Flexiple
flexiple.com › javascript › flatten-array-javascript
JavaScript: Flatten an array using different methods - Flexiple
Easily flatten arrays in JavaScript with our straightforward guide. Learn how to streamline your code and efficiently manipulate nested arrays.
🌐
4Geeks
4geeks.com › how-to › javascript-array-flatten
How to flatten an array in JavaScript?
July 16, 2025 - There are different ways to flatten an array in JavaScript, in the following examples we are going to see the three most popular ways to flatten an array using a recursive function, a loop, and of course the JavaScript flat() method.
🌐
GeeksforGeeks
geeksforgeeks.org › javascript-array-flat-method
JavaScript Array flat() Method | GeeksforGeeks
July 12, 2024 - The Javascript arr.flat() method was introduced in ES2019. The flat() method in JavaScript creates a new array with all sub-array elements concatenated into it recursively up to the specified depth.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › flatMap
Array.prototype.flatMap() - JavaScript - MDN Web Docs
Note that in this particular case the flatMap approach is slower than the for-loop approach — due to the creation of temporary arrays that must be garbage collected, as well as the return array not needing to be frequently resized. However, flatMap may still be the correct solution in cases where its flexibility and readability are desired. ... const arr = [1, 2, 3, 4]; arr.map((x) => [x * 2]); // [[2], [4], [6], [8]] arr.flatMap((x) => [x * 2]); // [2, 4, 6, 8] // only one level is flattened arr.flatMap((x) => [[x * 2]]); // [[2], [4], [6], [8]]
🌐
Java Script
jsoperators.hashnode.dev › array-flatten-in-javascript
Array flattening in javaScript
3 weeks ago - In this blog, we learned what nested arrays are and how to convert them into a single array. We also explored the use cases and interview perspectives of array flattening with practical code examples. #javascript#frontend-development#web-development#chaicode
🌐
SamanthaMing
samanthaming.com › tidbits › 71-how-to-flatten-array-using-array-flat
Flatten Array using Array.flat() in JavaScript | SamanthaMing.com
It was always complicated to flatten an array in JS. Not anymore! ES2019 introduced a new method that flattens arrays with Array.flat()...
🌐
Hashnode
arrayblog.hashnode.dev › array-flatten-in-javascript
Array Flatten in JavaScript
1 month ago - This post explains what nested arrays are, why and when you’d want to flatten them, several approaches to flattening in JavaScript, step‑by‑step visuals, interview-style problems with solutions, and practical suggestions for real projects.
🌐
Medium
claire-deboer.medium.com › how-to-flatten-an-array-in-javascript-5650ad6a7b8f
How to Flatten An Array in JavaScript | by Claire DeBoer | Medium
June 9, 2021 - Introduced as of ES2019, flat() returns a new array which is the flattened version of the original, removing any empty slots in the array. It works on most modern browsers. There is an optional argument known as depth which is the number of ...
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.flat()
Array.prototype.flat() - JavaScript Tutorial
November 7, 2024 - The following example uses the flat() method to flatten an array of numbers: const numbers = [1, 2, [3, 4, 5]]; const flatNumbers = numbers.flat(); console.log({ flatNumbers }); console.log({ numbers });Code language: JavaScript (javascript)
🌐
freeCodeCamp
freecodecamp.org › news › flat-and-flatmap-javascript-array-methods
How to Use the flat() and flatMap() Methods to Flatten Arrays in JavaScript
July 26, 2022 - In this article I'm going to explain how to use the new array methods introduced in ES2019 (EcmaScript 2019) – flat() and flatMap(). You use these methods to flatten arrays. The methods are very useful and easy to use.
🌐
Vultr Docs
docs.vultr.com › javascript › standard-library › Array › flat
JavaScript Array flat() - Flatten Nested Arrays | Vultr Docs
November 28, 2024 - The flat() method in JavaScript is called on an array and returns a new array where all sub-array elements concatenated into it recursively up to the specified depth. Define an array that contains nested arrays.
🌐
CodeBurst
codeburst.io › how-to-flatten-a-nested-javascript-array-628e01b85512
How to Flatten a Nested Javascript Array | by Cynthia Okoliezeh | codeburst
August 12, 2020 - The flat()method has an optional argument known as depth (the number of levels to flatten the array) and returns a new array - flattened version of the original array, removing any array hole (empty slot(s) in the array).