Skip to content

JSArray.Fill

boxgaming edited this page Jul 25, 2026 · 5 revisions

Changes all elements within a range of indices in an array to a static value. It returns the modified array.

Syntax

result = JSArray.Fill ( a, value, start%, end% )

Parameters

  • The a parameter contains the native Javascript array on which the operation will be performed.
  • The value parameter specifies the number, string or object.
  • The optional start% parameter specifies the index at which the fill operation will start. If not specified, the entire array will be filled with the provided value.
  • The optional end% parameter specifies the index at which the fill operation will stop.

Example

Import JSArray From "lib/lang/array.bas"

Dim numArray As Object
numArray = JSArray.Create(1, 2, 3, 4)

' Fill with 0 from position 2 until position 4
numArray = JSArray.Fill(numArray, 0, 2, 4)
Print JSArray.Join(numArray)

' Fill with 5 from position 1
numArray = JSArray.Fill(numArray, 5, 1)
Print JSArray.Join(numArray)

numArray = JSArray.Fill(numArray, 6)
Print JSArray.Join(numArray)

Output

1,2,0,0
1,5,5,5
6,6,6,6

See Also

JSArray.Create
JSArray.Join
Javascript - Array.fill()

Clone this wiki locally