// flat 将多维数组转为地位数组
const arr = [1,2,3,4,[5,6]];
console.log(arr);      //[1,2,3,4,5,6]

cosnt arr1 = [1,2,3,4,[5,6,[7,8]]];
console.log(arr1.flat(2));      //[1,2,3,4,5,6,7,8]

// flatMap 将低位数组转为多维数组
const arr2 = [1,2,3,4];
const result = arr2.map(item=> [item*10]);
console.log(result); // [[10],[20],[30],[40]]

const result2 = arr2.flatMap(item=> [item*10]);
console.log(result2); // [10,20,30,40]

相关文章:

  • 2019-03-02
  • 2021-12-18
  • 2021-11-02
  • 2021-10-20
  • 2021-11-23
  • 2021-09-18
  • 2021-11-19
猜你喜欢
  • 2021-06-30
  • 2021-11-19
  • 2021-11-19
  • 2021-11-19
  • 2021-08-30
  • 2021-05-30
  • 2021-11-19
相关资源
相似解决方案