Namespace: Array

utilx. Array

utilx.Array
Source:

Methods

(static) assign(array, index, value) → {number|undefined}

The Array.assign() method assigns a value to a specific element of an array and returns the new length of the array.
Parameters:
Name Type Description
array ArrayLike
index NumberLike
value *
Source:
Returns:
Type
number | undefined

(static) contains(array, searchElement, fromIndexopt) → {boolean}

Returns true if the specified searchElement is in the specified array. Using strict equality (the same method used by the === comparison operator).
Parameters:
Name Type Attributes Description
array ArrayLike
searchElement Object
fromIndex number <optional>
Source:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
boolean

(static) copyWithin(array, target, startopt, endopt) → {Array}

With this method, every element of array from start up to but not including end is assigned value.
Parameters:
Name Type Attributes Description
array ArrayLike
target number
start number <optional>
end number <optional>
Source:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
Array

(static) every(array, fn, thisArgopt) → {boolean}

Tests whether all elements in the array pass the test implemented by the provided function.
Parameters:
Name Type Attributes Description
array ArrayLike
fn everyCallback
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
boolean

(static) fill(array, value, startopt, endopt) → {Array}

With this method, fill every element of array from start up to but not including end is assigned value.
Parameters:
Name Type Attributes Description
array ArrayLike
value *
start number <optional>
end number <optional>
Source:
See:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
Array

(static) filter(array, fn, thisArgopt) → {Array}

Creates a new array with all elements that pass the test implemented by the provided function.
Parameters:
Name Type Attributes Description
array ArrayLike
fn function
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
Array

(static) find(array, fn, thisArgopt) → {*}

This method returns a value in the array, if an element in the array satisfies the provided testing function. Otherwise undefined is returned.
Parameters:
Name Type Attributes Description
array ArrayLike
fn findCallback
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
*

(static) findIndex(array, fn, thisArgopt) → {number}

This method returns an index in the array, if an element in the array satisfies the provided testing function. Otherwise -1 is returned.
Parameters:
Name Type Attributes Description
array ArrayLike
fn findIndexCallback
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
number

(static) first(inputArg) → {*}

Returns the first element of an array; otherwise returns undefined.
Parameters:
Name Type Description
inputArg ArrayLike
Source:
Returns:
Type
*

(static) forAll(array, fn, thisArgopt) → {undefined}

Executes a provided function once per array element position. Unlike forEach, this method treats the array as dense and allows a some like break.
Parameters:
Name Type Attributes Description
array ArrayLike
fn someCallback
thisArg * <optional>
Source:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
undefined

(static) forEach(array, fn, thisArgopt) → {undefined}

Executes a provided function once per array element.
Parameters:
Name Type Attributes Description
array ArrayLike
fn forEachCallback
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
undefined

(static) from(arrayLike, mapfnopt, thisArgopt) → {Array}

Converts a single argument that is an array-like object or list (eg. arguments, NodeList, DOMTokenList (used by classList), NamedNodeMap (used by attributes property)) into a new Array() and returns it.
Parameters:
Name Type Attributes Description
arrayLike ArrayLike
mapfn fromCallback <optional>
thisArg * <optional>
Source:
Returns:
Type
Array

(static) indexOf(array, searchElement, fromIndexopt) → {number}

This method returns the first index at which a given element can be found in the array, or -1 if it is not present.
Parameters:
Name Type Attributes Description
array ArrayLike
searchElement Object
fromIndex number <optional>
Source:
See:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
number

(static) isArray(inputArg) → {boolean}

The function takes one argument inputArg, and returns the Boolean value true if the argument is an object whose class internal property is "Array"; otherwise it returns false.
Parameters:
Name Type Description
inputArg *
Source:
See:
Returns:
Type
boolean

(static) isEmpty(inputArg) → {boolean|null}

The function takes one argument inputArg, if the argument is an object whose class internal property is "Array" or is an Object whose class internal property is "Arguments"; returns true if length is zero otherwise it returns false. Otherwise returns null if the argument does not match the rquirements.
Parameters:
Name Type Description
inputArg ArrayLike
Source:
Returns:
Type
boolean | null

(static) join(inputArg, separatoropt) → {string}

The arrayJoin() method joins all elements of an array into a string. The separator is converted to a string if necessary. If omitted, the array elements are separated with a comma.
Parameters:
Name Type Attributes Description
inputArg ArrayLike
separator string <optional>
Source:
See:
Throws:
if inputArg is null or {@link undefined}.
Type
TypeError
Returns:
Type
string

(static) last(inputArg) → {*}

Returns the last element of an array; otherwise returns undefined.
Parameters:
Name Type Description
inputArg ArrayLike
Source:
Returns:
Type
*

(static) lastIndexOf(array, searchElement, fromIndexopt) → {number}

This method returns the first index at which a given element can be found in the array, or -1 if it is not present.
Parameters:
Name Type Attributes Description
array ArrayLike
searchElement Object
fromIndex number <optional>
Source:
See:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
number

(static) map(array, fn, thisArgopt) → {Array}

Creates a new array with the results of calling a provided function on every element in this array.
Parameters:
Name Type Attributes Description
array ArrayLike
fn mapCallback
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
Array

(static) of(…varArgsopt) → {Array}

This method creates a new Array instance with a variable number of arguments, regardless of number or type of the arguments.
Parameters:
Name Type Attributes Description
varArgs * <optional>
<repeatable>
Source:
See:
Returns:
Type
Array

(static) powerSet(array) → {Array.<Array>}

This method calculates the Power Set of a given array.
Parameters:
Name Type Description
array ArrayLike | string
Source:
See:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
Array.<Array>

(static) push(array, …varArgsopt) → {number}

The Array.push() method adds one or more elements to the end of an array and returns the new length of the array.
Parameters:
Name Type Attributes Description
array ArrayLike
varArgs * <optional>
<repeatable>
Source:
See:
Returns:
Type
number

(static) reduce(array, fn, initialValueopt) → {*}

Apply a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
Parameters:
Name Type Attributes Description
array ArrayLike
fn function
initialValue * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
*

(static) reduceRight(array, fn, initialValueopt) → {*}

This method applies a function against an accumulator and each value of the array (from left-to-right) as to reduce it to a single value.
Parameters:
Name Type Attributes Description
array ArrayLike
fn function
initialValue * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
*

(static) shuffle(array, roundsopt) → {Array}

This method performs Fisher-Yates shuffle for randomly shuffling a set.
Parameters:
Name Type Attributes Description
array ArrayLike
rounds NumberLike <optional>
Source:
See:
Throws:
if array is null or {@link undefined}
Type
TypeError
Returns:
Type
Array

(static) slice(array, startopt, endopt) → {Array}

Creates a new array from arguments, starting at start and ending at end.
Parameters:
Name Type Attributes Description
array ArrayLike
start NumberLike <optional>
end NumberLike <optional>
Source:
See:
Returns:
Type
Array

(static) some(array, fn, thisArgopt) → {boolean}

Tests whether some element in the array passes the test implemented by the provided function.
Parameters:
Name Type Attributes Description
array ArrayLike
fn someCallback
thisArg * <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if fn is not a function
    Type
    TypeError
Returns:
Type
boolean

(static) sort(array, compareFNopt) → {ArrayLike}

This method sorts the elements of an array in place and returns the array. The sort may be unstable depending on the browser. The default sort order is lexicographic (not numeric).
Parameters:
Name Type Attributes Description
array ArrayLike
compareFN function <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if compareFN is defined and is not a function
    Type
    TypeError
Returns:
same type as supplied array argument.
Type
ArrayLike

(static) splice(array, start, deleteCountopt, …elementopt) → {Array}

The $.Array.splice() method changes the content of an array, adding new elements while removing old elements.
Parameters:
Name Type Attributes Description
array ArrayLike
start number
deleteCount number <optional>
element * <optional>
<repeatable>
Source:
See:
Returns:
Type
Array

(static) stableSort(array, compareFNopt) → {ArrayLike}

This method method sorts the elements of an array in place and returns the array. This is a stable sort. The default sort order is lexicographic (not numeric).
Parameters:
Name Type Attributes Description
array ArrayLike
compareFN function <optional>
Source:
See:
Throws:
  • if array is null or {@link undefined}
    Type
    TypeError
  • if compareFN is defined and is not a function
    Type
    TypeError
Returns:
same type as supplied array argument.
Type
ArrayLike

(static) toObject(array) → {Object}

Convert an array to a plain object representation.
Parameters:
Name Type Description
array ArrayLike
Source:
Returns:
Type
Object

(static) unique(array, equalFnopt, thisArgopt) → {Array}

This method creates a new array of unique occurences using the strictEqual comparison. The new array is ordered as per the original array. A function can be provided as an alternative comparison method.
Parameters:
Name Type Attributes Description
array ArrayLike
equalFn equalityFn <optional>
thisArg * <optional>
Source:
Throws:
  • if array is null or {@link undefined}.
    Type
    TypeError
  • if equalFn is not a function.
    Type
    TypeError
Returns:
Type
Array

(static) unshift(array, …varArgsopt) → {number}

The Array.unshift() method adds one or more elements to the beginning of an array and returns the new length of the array.
Parameters:
Name Type Attributes Description
array ArrayLike
varArgs * <optional>
<repeatable>
Source:
See:
Returns:
Type
number