Namespace: arr

FooTable.arr

This namespace contains commonly used array utility methods.

Methods

(static) any(array, whereopt) → {boolean}

Get a boolean value indicating if any item exists in the supplied array that optionally matches the supplied where function.
Parameters:
Name Type Attributes Description
array Array The array to check.
where function <optional>
[Optional] This function must return a boolean value, true indicates that the current item is a valid match.
Returns:
Type
boolean

(static) contains(array, value) → {boolean}

Checks if the supplied value exists in the array.
Parameters:
Name Type Description
array Array The array to check.
value * The value to check for.
Returns:
Type
boolean

(static) delete(array, item) → {*|null}

Deletes a single item from the array. The item if removed is returned.
Parameters:
Name Type Description
array Array The array to iterate and delete the item from.
item * The item to find and delete.
Returns:
Type
* | null

(static) each(array, func)

Iterates over each item in the supplied array and performs the supplied function passing in the current item as the first argument.
Parameters:
Name Type Description
array Array The array to iterate
func function The function to execute for each item. The first argument supplied to this function is the current item and the second is the current index.

(static) first(array, whereopt) → {*|null}

Get the first item in the supplied array that optionally matches the supplied where function. If no item is found null is returned.
Parameters:
Name Type Attributes Description
array Array The array to get the item from.
where function <optional>
[Optional] This function must return a boolean value, true indicates that the current item can be returned.
Returns:
Type
* | null

(static) get(array, where) → {Array}

Get all items in the supplied array that optionally matches the supplied where function. If no items are found an empty array is returned.
Parameters:
Name Type Description
array Array The array to get items from.
where function This function must return a boolean value, true includes the item in the result array.
Returns:
Type
Array

(static) map(array, getter) → {*|null}

Creates a new array from the results of the supplied getter function. If no items are found an empty array is returned, to exclude an item from the results return null.
Parameters:
Name Type Description
array Array The array to iterate.
getter function This function must return either a new value or null. The first argument is the result being returned at this point in the iteration. The second argument is the current item being iterated.
Returns:
Type
* | null

(static) remove(array, where) → {*}

Removes items from the array matching the supplied where function. All removed items are returned in a new array.
Parameters:
Name Type Description
array Array The array to iterate and remove items from.
where function This function must return a boolean value, true includes the item in the result array.
Returns:
Type
*

(static) replace(array, oldItem, newItem)

Replaces a single item in the array with a new one.
Parameters:
Name Type Description
array Array The array to iterate and replace the item in.
oldItem * The item to be replaced.
newItem * The item to be inserted.