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
🌐
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.
🌐
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]
🌐
4Geeks
4geeks.com › how-to › javascript-array-flatten
How to flatten an array in JavaScript?
July 16, 2025 - Flattening an array in JavaScript ... can be done in many different ways but the easiest way to achieve this is by using the JavaScript flat() method, as shown in the following example....
🌐
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.
🌐
Scaler
scaler.com › home › topics › flatten an array in javascript
Flatten an Array in JavaScript - Scaler Topics
May 4, 2023 - Learn various methods of how to flatten an array in JavaScript in detail along with syntax and code examples on Scaler Topics.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.flat()
JavaScript Array flat()
November 7, 2024 - In this tutorial, you'll learn how to use the JavaScript Array flat() method to flatten an array with nested array to a specified depth.
🌐
Flexiple
flexiple.com › javascript › flatten-array-javascript
JavaScript: Flatten an array using different methods - Flexiple
March 11, 2022 - Easily flatten arrays in JavaScript with our straightforward guide. Learn how to streamline your code and efficiently manipulate nested arrays.
Find elsewhere
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript array methods › array.prototype.flat()
Array.prototype.flat() - JavaScript Tutorial
November 7, 2024 - In this tutorial, you'll learn how to use the JavaScript Array flat() method to flatten an array with nested array to a specified depth.
🌐
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()...
🌐
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.
🌐
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
🌐
ZetCode
zetcode.com › js-array › flat
JavaScript flat - flattening arrays in JS
April 4, 2025 - JavaScript flat tutorial shows how to flatten arrays in JavaScript. The tutorial provides numerous examples to demonstrate array flattening in JS.
🌐
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]]
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › javascript-array-flat-method
JavaScript Array flat() Method - GeeksforGeeks
July 15, 2025 - The Javascript arr.flat() method ... in JavaScript creates a new array with all sub-array elements concatenated into it recursively up to the specified depth. If no depth is provided, it defaults to 1. ... depth: It specifies, how deep the nested ...
🌐
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 ...
🌐
YouTube
youtube.com › watch
How to Flatten an Array in JavaScript |Use flat(), Recursion & Other Methods to Handle Nested Arrays - YouTube
Working with nested arrays in JavaScript? In this beginner-friendly tutorial, you'll learn how to flatten an array in JavaScript using multiple methods like ...
Published   July 8, 2025
🌐
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 ... depth. Define an array that contains nested arrays. Use the flat() method without specifying a depth to flatten the array one level deep....
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › javascript flatten array
JavaScript Flatten Array | 11 Amazing Examples of JavaScript Flatten Array
April 1, 2023 - Guide to JavaScript Flatten Array. Here we discuss the Introduction to JavaScript Flatten Array and its different Examples along with Code.
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
CoreUI
coreui.io › answers › how-to-flatten-a-nested-array-in-javascript
How to flatten a nested array in JavaScript · CoreUI
September 20, 2025 - Use the flat() method to convert nested arrays into a single-level array. const nested = [1, [2, 3], [4, [5, 6]]] const flattened = nested.flat() // Result: [1, 2, 3, 4, [5, 6]]