FunctionIdentifies the base type of array elements
The array or array-like object to flatten
Optionaldepth: numberThe flattening depth, defaults to 1. Use Infinity for complete flattening
A new flattened array
arrFlatten([1, [2, 3], [4, [5, 6]]]); // [1, 2, 3, 4, [5, 6]]
arrFlatten([1, [2, 3], [4, [5, 6]]], 2); // [1, 2, 3, 4, 5, 6]
arrFlatten([1, [2, 3], [4, [5, 6]]], Infinity); // [1, 2, 3, 4, 5, 6]
arrFlatten([1, 2, 3]); // [1, 2, 3]
arrFlatten([]); // []
// With array-like objects
arrFlatten({ length: 2, 0: 1, 1: [2, 3] }); // [1, 2, 3]
The arrFlatten() method returns a new array with all sub-array elements flattened up to the specified depth (default 1).