Javascript examples for Array:fill
The fill() method fills all the elements in an array with a value.
Parameter | Description |
---|---|
value | Required. The value to fill the array with |
start | Optional. The index to start filling the array (default is 0) |
end | Optional. The index to stop filling the array (default is array.length) |
An Array, the changed array
The following code shows how to Fill all the array elements with a value:
<!DOCTYPE html> <html> <body> <button onclick="myFunction()">Test</button> <p id="demo"></p> <script> var fruits = ["a","b","c","d","e"]; document.getElementById("demo").innerHTML = fruits; function myFunction() {//from w w w. j a va 2 s.c om document.getElementById("demo").innerHTML = fruits.fill("A",2,4); } </script> </body> </html>