Array-Helper-Functions
Useful Array functions not built into the Javascript Array Object.
Functions
- erase(array, item)
-
Erase a particle item / element /index from the provided Array
- forEachReverse(array, funct)
-
Loop through all the elements of an Array backwards and call a function for each index
-
random(array) ⇒
*
-
Get a random element from the array
- shuffle(array)
-
Randomly shuffle the elements in the Array
-
clone(array) ⇒
Array
-
Return a copy or clone of the Array that doesn't have reference to the original
erase(array, item)
Erase a specific item / element /index from the provided Array
Param | Type | Description |
---|---|---|
array | Array |
Array to erase the item from |
item | * |
The element or item to remove |
forEachReverse(array, funct)
Loop through all the elements of an Array backwards and call a function for each index
Param | Type | Description |
---|---|---|
array | Array |
The Array to loop through |
funct | function |
Function to call for each index |
Example
- forEachReverse([0, 1], (item) => { console.log(item) }); // 1, 0
*
random(array) ⇒ Get a random element from the array
Returns: *
- - The random Array index data
Param | Type | Description |
---|---|---|
array | Array |
Array to get the random element from |
shuffle(array)
Randomly shuffle the elements in the Array
Param | Type | Description |
---|---|---|
array | Array |
Array to shuffle the contents of |
Example
- shuffle(array);
Array
clone(array) ⇒ Return a copy or clone of the Array that doesn't have reference to the original
Returns: Array
- - copied Array
Param | Type | Description |
---|---|---|
array | Array |
Array you want to copy |
Example
- let newArray = array.clone();