Skip to content

JSArray.Unshift

boxgaming edited this page Jul 25, 2026 · 2 revisions

Adds the specified elements to the beginning of an array.

Syntax

JSArray.Unshift a, item1 [, item2, ... itemN]

Parameters

  • The a parameter contains the native Javascript array on which the operation will be performed.
  • One or more item parameters can be passed to the method. Items will be added to the beginning of the array in the order they appear in the list.

Example

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

Dim numbers As Object
numbers = JSArray.Create("one", "two")

JSArray.Unshift numbers, "three"
Print JSArray.Length(numbers)
Print JSArray.Join(numbers)

JSArray.Unshift numbers, "four", "five", "six"
Print JSArray.Length(numbers)
Print JSArray.Join(numbers)

Output

3
three,one,two
6
four,five,six,three,one,two

See Also

JSArray.Create
JSArray.Join
JSArray.Length
JSArray.Push
JSArray.Shift
Javascript - Array.unshift()

Clone this wiki locally