Array

Use array to store multiple elements

Constructor

Construct an array using [] syntax

Fields

size: Return the size of the array.

Methods

As of 1.4.3+. You can use most of lodash function on an array: https://lodash.com/docs/4.17.15

Available functions:

push
number push(element: any)

Adds one element to the end of an array and returns the new length of the array.

Parameters
element The element to add
Return
number The new length of the array
pop
any pop()

Removes the last element from an array and returns that element. This method changes the length of the array.

Return
any The last element in the array
unshift
number unshift(element: any)

Adds one element to the beginning of an array and returns the new length of the array.

Parameters
element The element to add
Return
number The new length of the array
shift
any shift()

Removes the first element from an array and returns that element. This method changes the length of the array.

Return
any The first element in the array
insertAt
number insertAt(index: number, element: any)

Inserts one element at the index and returns the new length of the array.

Parameters
index The index to insert. index >= 0 and index < size
element The element to insert
Return
number The new length of the array
insertRange
number insertRange(index: number, elements: array)

Inserts elements at the index and returns the new length of the array.

Parameters
index The index to insert. index >= 0 and index < size
elements The array of elements to insert
Return
number The new length of the array
removeAt
any removeAt(index: number)

Removes one element at the index and returns the new length of the array.

Parameters
index The index of the element to remove. index >= 0 and index < size
Return
number The new length of the array
removeRange
number removeRange(startIndex: number, endIndex: number)

Removes elements from startIndex to endIndex and returns the new length of the array.

Parameters
startIndex The start index. index >= 0 and index < size
endIndex The end index. index >= 0 and index < size
Return
number The new length of the array
slice
array slice(startIndex: number, endIndex: number)

Returns a shallow copy of a portion of an array into a new array selected from startIndex to endIndex (end not included). The original array will not be modified.

Parameters
startIndex The start index. index >= 0 and index < size
endIndex The end index. index >= 0 and index <= size
Return
array The new array
concat
array concat(elements: array)

Merges two arrays. This method does not change the existing arrays, but instead returns a new array.

Parameters
elements The array to merge
Return
array The new merged array
clear
number clear()

Removes all elements in the array. Return 0

Return
number The new size which is 0
clone
array clone()

Shallow copy all the elements of the array

Return
array The new array

© 2024 - Macrorify by KoK-CODE