JavaScript Array fill()
Example
Fill all the array elements with a static value:
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi");
Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The fill() method fills specified elements in an array with a static value.
You can specify the position of where to start and end the filling. If not specified, all elements will be filled.
fill() overwrites the original array.
Browser Support
The numbers in the table specify the first browser version that fully supports the method:
| Chrome 45 | Edge 12 | Firefox 31 | Safari 7.1 | Opera 32 |
| Sep 2015 | Jul 2015 | Jul 2014 | Sep 2014 | Sep 2015 |
The fill() method is not supported in Internet Explorer.
Syntax
array.fill(value, start, end)
Parameter Values
| 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) |
Technical Details
| Return Value: | An Array, the changed array |
|---|---|
| JavaScript Version: | ECMAScript 6 |
More Examples
Example
Fill the last two array elements with "Kiwi":
const fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi", 2, 4);
Try it Yourself »

