1.1.0 • Published 5 years ago
@ishoa/array-helpers v1.1.0
Array-Helper-Functions
Useful Array functions not built into the Javascript Array Object.
Functions
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);
clone(array) ⇒ 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();