loverajoel / jstips

This is about useful JS tips!
http://jstips.co
GNU General Public License v3.0
12.5k stars 803 forks source link

Update 2016-02-07-flattening-multidimensional-arrays-in-javascript.md - Add one solution in ES6 #340

Closed richzw closed 8 years ago

richzw commented 8 years ago

Add one solution in ES6 for 2016-02-07 tips

TL;DR;

Using spread operator in ES6

var myNewArray4 = [].concat(...myArray);
console.log(myNewArray4);
// [1, 2, 3, 4, 5, 6, 7, 8, 9]

Username

@zangw

Extra

To recursively flattens array, one good method flattenDeep could do that. However, the flatten in underscore only be flattened a single level.

loverajoel commented 8 years ago

thanks!!