JavaScript Array fill() Method
Clash Royale CLAN TAG#URR8PPP
<!--
main_leaderboard, all: [728,90][970,90][320,50][468,60]-->
JavaScript Array fill() Method
❮ JavaScript Array Reference
Example
Fill all the array elements with a static value:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi");
<!--
The result of fruits will be:
Kiwi,Kiwi,Kiwi,Kiwi
-->Try it Yourself »
More "Try it Yourself" examples below.
Definition and Usage
The fill() method fills all the elements in an array with a static value.
It is possible to specify the index for starting and ending fill(). By
default it changes the whole array.
Browser Support
The numbers in the table specify the first browser version that fully supports the method.
Method | |||||
---|---|---|---|---|---|
fill() | 45.0 | 12.0 | 31.0 | 7.1 | 32.0 |
Note: The fill() method is not supported in Internet
Explorer 11 and earlier versions.
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) |
<!--
mid_content, all: [300,250][336,280][728,90][970,250][970,90][320,50][468,60]-->
Technical Details
Return Value: | An Array, the changed array |
---|---|
JavaScript Version: | ECMAScript 6 |
More Examples
Example
Fill the last two array elements with a static value:
var fruits = ["Banana", "Orange", "Apple", "Mango"];
fruits.fill("Kiwi", 2, 4);
<!--
The output of the code above will be:
Banana,Orange,Kiwi,Kiwi
-->Try it Yourself »
❮ JavaScript Array Reference