ES10 flat 和flatMap

//flat 平
//将多维数组转化为低位数组
const arr = [1,2,3,4,[5,6]]; 
const arr = [1,2,3,4,[5,6,[7,8,9]]];
//参数为深度 是一个数字
console.log(arr.flat(2)); // 2代表深度

//flatMap
const arr1 = [1,2,3,4];
const result = arr1.flatMap(item => [item * 10]);
console.log(result);

posted on 2021-01-13 16:33  家有糖果  阅读(92)  评论(0)    收藏  举报

导航