Array.from创建指定长度的数组,map生成新内容的数组

      const arr = Array.from({ length: 10 });
      console.log(arr); //[undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined, undefined]
      const arr2 = arr.map((item) => 1); 
      console.log(arr2); //[1, 1, 1, 1, 1, 1, 1, 1, 1, 1]

posted @ 2021-12-23 11:42  徐同保  阅读(0)  评论(0编辑  收藏  举报  来源