JavaScript Array fill() Method
JavaScript Array fill() Method
The fill()
method fills (modifies) all the elements of an array from a start index to an end index with a static value.
Note: This method overwrites the original array.
Fill All Elements in an Array
In the following example, we will omit the start index and end value to fill all the elements in an array.
Example
Syntax
Parameter Values
Value | Type | Explanation |
---|---|---|
value | Required | Specifies a value to fill an array. |
start | Optional | Specifies the starting position. If start is omitted, the default value is 0. |
end | Optional | Specifies the ending position. If end is omitted, the default value is the length of an array. |
Fill Specific Elements in an Array
In the following example, we will specify the start index and end value to fill specific elements in an array.
Example
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.