The Array
type provides various methods for array manipulation, searching, and ordering.
Adds an item to the end of the array and returns the modified array.
Parameters:
item
: The item to add to the end of the array.Return Type: Array
Example:
Extends the array by appending all items from another array and returns the modified array.
Parameters:
array
: The array containing items to append.Return Type: Array
Example:
Inserts an item at the specified position in the array and returns the modified array.
Parameters:
index
: The index before which to insert the item.item
: The item to insert.Return Type: Array
Example:
Removes the first occurrence of the specified item from the array and returns the modified array.
Parameters:
item
: The item to remove.Return Type: Array
Example:
Removes and returns the item at the specified position. If no index is provided, removes and returns the last item.
Parameters:
index
: The index of the item to remove (optional).Return Type: The removed item.
Example:
Removes all items from the array and returns the modified (empty) array.
Return Type: Array
Example:
Returns the index of the first occurrence of the specified item within the optional start and end range.
Parameters:
item
: The item to search for.start
: The index to start the search from (optional).end
: The index to end the search at (optional).Return Type: Number
(Returns -1 if the item is not found)
Example:
Returns the number of occurrences of the specified item in the array.
Parameters:
item
: The item to count.Return Type: Number
Example:
Sorts the items of the array in place and returns the modified array.
Parameters:
reverse
: Whether to sort in descending order (optional, default: false).Return Type: Array
Example:
Reverses the elements of the array in place and returns the modified array.
Return Type: Array
Example:
Returns a shallow copy of a portion of the array into a new array, without modifying the original array.
Parameters:
start
: The beginning index (can be negative to index from the end).end
: The end index (optional, can be negative to index from the end).Return Type: Array
Example: