js .flat 1

js .flat

var multiDimensionArray = [["a"],["b","c"],["d"]]; //array of arrays
var flatArray = Array.prototype.concat.apply([], multiDimensionArray); //flatten array of arrays
console.log(flatArray); // [ "a","b","c","d"];

Here is what the above code is Doing:
1. We have an array of arrays.
2. We use the apply() method to call the concat() method on the first array.
3. The concat() method takes in the array of arrays as its argument.
4. The concat() method returns a new array with the contents of the array of arrays.

Similar Posts