Array flattening: convert multidimensional arrays into one-dimensional arrays, flatten nested arrays

1. es6's flat()
flat() will flatten the nested array and return a new array without changing the original array.
The default leveling depth is 1.
If the original array has space, the flat() method will skip the space.

var arr=[1,[2,3,[4,5,[6,7]]]];
arr.flat(); //默认深度1: arr=[1, 2, 3, [4,5, [6, 7]]]
arr.flat(2);//深度为2: arr= [1, 2, 3, 4, 5, [6, 7]]
arr.flat(Infinity);//深度无限:arr=[1, 2, 3, 4, 5, 6, 7] 

(notes, to be continued)

Guess you like

Origin blog.csdn.net/qq_41612593/article/details/115768347