Array.fill

fill — Fills an array with a static value.

Description

Array.fill(mixed value, [integer start, [integer end]])

Parameters

Name Description Type Default Optional
value mixed No
start integer Yes
end integer Yes

Return values

The array with the filled values.

Examples

Example #1 – fill example

The array is overwritten when overwriting.

var array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.fill(3)); // [3, 3, 3, 3, 3, 3, 3] console.log(array); // [3, 3, 3, 3, 3, 3, 3] array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.fill(3, 2)); // [2, 4, 3, 3, 3, 3, 3] console.log(array); // [2, 4, 3, 3, 3, 3, 3] array = [2, 4, 8, 4, 16, 4, 32]; console.log(array.fill(3, 2, 4)); // [2, 4, 3, 3, 16, 4, 32] console.log(array); // [2, 4, 3, 3, 16, 4, 32]

External references