Array.prototype.fill >= 0.1.3
Purpose
Fill all the elements of the array from a start index to an end index with a static value
Syntax
Array#fill
(
Objectvalue
Numberstart= 0
Numberend= this.length
);
Parameters
value
- Value to fill an array with
start
- Start index
end
- End index (non-inclusive)
Examples
Fill an array
var arr = new Array(10);>>> [undefined × 10]
arr.fill(1);>>> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
Fill an array starting at a given index
var arr = new Array(10);>>> [undefined × 10]
arr.fill(1);>>> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
arr.fill(2, 2)>>> [1, 1, 2, 2, 2, 2, 2, 2, 2, 2]
Fill an array starting at an index and until an index
var arr = new Array(10);>>> [undefined × 10]
arr.fill(1);>>> [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
arr.fill(3, 2, 4)>>> [1, 1, 3, 3, 1, 1, 1, 1, 1, 1]
Comments