fill

array

Fills elements of array with value from start up to, but not including, end.

Signature

fill<T>(array: any[], value: T, start?: number, end?: number): any[]

Parameters

NameTypeDescription
arrayany[]The array to fill
valueTThe value to fill array with
start?numberThe start positionDefault: 0
end?numberThe end position

Returns

any[] - Returns array

Examples

Fill entire array

import { fill } from 'dashlite'

const array = [1, 2, 3]
fill(array, 'a')
console.log(array)

Output:

['a', 'a', 'a']

Fill with range

import { fill } from 'dashlite'

const result = fill([4, 6, 8, 10], '*', 1, 3)
console.log(result)

Output:

[4, '*', '*', 10]

Available since version 1.0.0