fill()
ES6+Fills all the elements of an array from a start index to an end index with a static value.
Syntax
array.fill(value, start, end)Parameters
value any Value to fill the array with
start number optionalStart index (default: 0)
end number optionalEnd index (default: array.length)
Return Value
Array
The modified array
Examples
JavaScript
const arr = [1, 2, 3, 4];
arr.fill(0, 1, 3);
console.log(arr); Output:
// [1, 0, 0, 4]