.fill(value)
Description
Parameters
Usage On Arrays
// Fill array with a string
arr = (1 to 5).fill("hello")
log arr // ["hello", "hello", "hello", "hello", "hello"]
// Fill array with a number
numbers = (1 to 3).fill(42)
log numbers // [42, 42, 42]
// Fill with other types
booleans = (1 to 4).fill(true) // [true, true, true, true]
objects = (1 to 2).fill({x: 10}) // [{x: 10}, {x: 10}]
// Common use case: Initialize array with default values
scores = (1 to 10).fill(0) // [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]Important Notes
Last updated