js的Array

 1)fill() 方法用一个固定值填充一个数组中从起始索引到终止索引内的全部元素。不包括终止索引。

   语法:fill(<value>,[start],[end]) 第一个参数必选,后面两个可选

   注意:该方法会更改元素数组

 1 const array1 = [1, 2, 3, 4];
 2 
 3 // fill with 0 from position 2 until position 4
 4 console.log(array1.fill(0, 2, 4));
 5 // expected output: [1, 2, 0, 0]
 6 
 7 // fill with 5 from position 1
 8 console.log(array1.fill(5, 1));
 9 // expected output: [1, 5, 5, 5]
10 
11 console.log(array1.fill(6));
12 // expected output: [6, 6, 6, 6]

创建一个长度为10的数组并初始默认值

new Array(spec.length).fill('0') 

实例下的prototype方法:文档:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Array

原文地址:https://www.cnblogs.com/zhizou/p/13633332.html