1 console.log( 2 [1, [2, 3, [4, 5]]] 3 .toString() 4 .split(",") 5 .map((item) => +item) 6 ); 7 //[ 1, 2, 3, 4, 5 ]
通过
[1, [2, 3, [4, 5]]].flat(Infinity)
实质:
Array.prototype.flat = function() { return this.toString().split(‘,‘).map(item => +item ) }
2023-10-13 20:14:10
1 console.log( 2 [1, [2, 3, [4, 5]]] 3 .toString() 4 .split(",") 5 .map((item) => +item) 6 ); 7 //[ 1, 2, 3, 4, 5 ]
通过
[1, [2, 3, [4, 5]]].flat(Infinity)
实质:
Array.prototype.flat = function() { return this.toString().split(‘,‘).map(item => +item ) }