fill() method fills specified elements in an array with a static value.
syntax ↴
fill(value, start, end) ↴
value Value to fill the array with. Note: all filled elements in the array will be this exact value.
start index at which to start filling. Default is 0.
end index at which to end filling. Default is array length.
fill() method overwrites the original array.
fill() method fills empty slots in sparse arrays with value as well.
fill() returns the modified array.
Start and end position can be specified. If not, all elements will be filled.
The first position is 0, the second is 1, ...
A negative number selects from the end of the array.
To create an array with five slots and populate it with the string 'hello' ↴
new Array(5).fill('hello'); returns ↴
['hello', 'hello', 'hello', 'hello', 'hello']
myArray.fill(value)
myArray.fill(value, start)
myArray.fill(value, start, end)