当只有第1个参数是默认设置数组的所有值为参数1的值。
当只有第1,2两个参数值设置从第2个值的位置到数组的末端利用参数1的值进行赋值。
同时还须要把稳的是不能对超出数组长度的值进行赋值。

请看下面的演示程序。
<!DOCTYPE html><html> <head> <title>数组的fill方法</title> <meta charset="utf-8"> </head> <body> <textarea style="height: 500px;width: 300px;" id="value"></textarea> </body> <script> let dom = document.getElementById("value"); let str=[] let a=new Array(5); str.push(`the init value is ${a}`); a.fill(1); str.push(`the a.fill(1) value is ${a}`); a.fill(2,1); str.push(`the a.fill(2,1) value is ${a}`); a.fill(3,3,5); str.push(`the a.fill(3,3,5) value is ${a}`); a.fill(3,5,10); str.push(`the a.fill(3,5,10) value is ${a}`); a.length=10 a.fill(3,5,10); str.push(`after set length is 10 the a.fill(3,5,10) value is ${a}`); dom.value =str.join("\n"); </script></html>
输出结果为:
从结果上我们可以看到上述的结论。但是利用fill对数组进行赋值还是有一些局限性的,只能赋值一部分的位置的值为一个相同的值。