Flatten multi-dimensional JavaScript arrays with ES6

Hopefully you already know that ES6 has made JavaScript really great. JavaScript went from pretty cool to oh-my-gosh-this-language-rules in one language spec update.

Here's a very handy way to flatten multi-dimensional (well, two dimensional, to be precise) arrays.

const multiDimensionalArray = [ [1, 2], [3, 4], [5, 6] ];
const flattenedArray = [].concat(...multiDimensionalArray);
console.log(flattenedArray) // [1, 2, 3, 4, 5, 6]

If you'd like to be notified when I publish new content, sign up for my mailing list in the navbar.

Check out my free videos on The Serverless Framework!