Rub Array Essential
arr = [9, 5, 1, 2, 3, 4, 0, -1]
access index
inclusive and exclusive range
To access the elements from the end of the list, we can use negative indices.
arr = [9, 5, 1, 2, 3, 4, 0, -1]
last element
arr[-1] => -1
or
The last element of the array can be accessed using
FIRST element
The first n elements of the array can be accessed using
Everything but the first n elements of the array can be accessed using
PUSH
push allows one to add an element to the end of the list.
INSERT
insert allows one to add one or more elements starting from a given index (shifting elements after the given index in the process).
UNSHIFT
unshift allows one or more elements to be added at the beginning of the list.
DELETE FROM ARRAY
arr = [5, 6, 5, 4, 3, 1, 2, 5, 4, 3, 3, 3]
Delete an element from the end of the array
Delete an element from the beginning of the array
Delete an element at a given position
Delete all occurrences of a given element
Non-Destructive Selection.
destructive behavior (change to the original array)