Array.fill
Array.fill
Function
Fills a range of the array with the specified value.
Syntax
array.fill(value, start, end)
Parameters
| Parameters | Type | Required | Default value | Description |
|---|---|---|---|---|
| value | Any | No | Empty | The value to write. |
| start | Int | No | 0 | Starting subscript; a negative number means counting backwards from the tail. |
| end | Int | No | Array length | End subscript, excluding this position; a negative number means backward calculation from the tail. |
Return value
| Type | Description |
|---|---|
| Array | Returns the original array object. |
Example
items = [1, 2, 3] result = items.fill(0, 1, 3) // Output: [1,0,0] print result
Notes
- This method will modify the original array.