1. 程式人生 > >[Javascript] Automate the process of flattening deeply nested arrays using ES2019's flat method

[Javascript] Automate the process of flattening deeply nested arrays using ES2019's flat method

prototype eas rip fin nbsp Language con may make

Among the features introduced to the language of JavaScript in ES2019 is Array.prototype.flat. In this lesson we‘ll see just how easy the flat method makes the process of unboxing arrays regardless of how deeply nested they may be.

Deep flatten:

var arr2 = [1, 2, [3, 4, [5, 6]]];
console.log(arr2.flat(Infinity)); 
// [1, 2, 3, 4, 5, 6]

[Javascript] Automate the process of flattening deeply nested arrays using ES2019's flat method