English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية
The fill() method uses a static value to fill all elements of the array from the start index to the end index.
array.fill(value, start, end)
var nums = [1, 2, 3, 4]); nums.fill(17);Test See‹/›
The numbers in the table specify the first browser version that fully supports the fill() method:
Method | |||||
fill() | 45 | 31 | Yes | 8 | Yes |
Parameter | Description |
---|---|
value | (Required)Value to fill the array with |
start | (Optional)Index to start filling the array. The default is 0 |
end | (Optional)Index to stop filling the array. The default value isthis.length |
Return value: | Modified array |
---|---|
JavaScript version: | ECMAScript 6 |
From position2To position4Fill 0:
var nums = [1, 2, 3, 4]); nums.fill(0, 2, 4);Test See‹/›
From position1Fill7:
var nums = [1, 2, 3, 4]); nums.fill(7, 1);Test See‹/›