Class: Array

Array

The JavaScript Array object.

new Array()

Source:
See:

Mixes In

Methods

<static> from(arrayLike) → {Array}

Creates a new Array instance from an array-like object.
Parameters:
Name Type Description
arrayLike Object

An array-like object to convert to an array.

This is a partial polyfill for the ES6-defined Array.from() function that only accepts array-like objects and does not support the optional mapFn or thisArg arguments.

Firebolt will not alter Array.from if it is already implemented by the browser. Furthermore, since Firebolt implements a subset of the ES6-defined functionality, code that works with Firebolt's shim will also work when browsers natively implement Array.from, so your code will be future-proof.

Source:
Returns:
Type
Array

<static> of(elementN) → {Array}

Creates a new Array instance with a variable number of arguments.
Parameters:
Name Type Argument Description
elementN * <repeatable>

Elements with which to populate the new array.

This is a complete polyfill for the ES6-defined Array.of() for browsers that have not implemented it function yet.

Source:
Returns:
Type
Array

clean() → {Array}

Returns a copy of the array with all "empty" items (as defined by Firebolt.isEmpty) removed.

Source:
See:
Returns:
Type
Array

A clean copy of the array.

clear()

Removes all elements from the array.

Source:

clone() → {Array}

Returns a duplicate of the array.

Source:
Returns:
Type
Array

A shallow copy of the array.

diff(*arrays) → {Array}

Returns a new array with all of the values of this array that are not in any of the input arrays (performs a set difference).

Parameters:
Name Type Argument Description
*arrays Array <repeatable>

A variable number of arrays or array-like objects.

Source:
Returns:
Type
Array
Example
[1, 2, 3, 4, 5].diff([5, 2, 10]); // -> [1, 3, 4]

each(callback(value,index,array)) → {Array}

Executes a function on each item in the array.
Parameters:
Name Type Description
callback(value,index,array) function

A function to be executed on each item in the array.

A generic iterator function is similar to Array#forEach() but with the following differences:

  1. this always refers to the current item in the iteration (the value argument to the callback).
  2. Returning false in the callback will cancel the iteration (similar to a break statement).
  3. The array is returned to allow for function chaining.
Source:
Returns:
Type
Array

this

equals(array) → {Boolean}

Determines if the arrays are equal by doing a shallow comparison of their elements using strict equality.

Note: The order of elements in the arrays DOES matter. The elements must be found in the same order for the arrays to be considered equal.

Parameters:
Name Type Description
array Array

Array or array-like object.

Source:
Throws:
TypeError
Throws an error if the input value is `null` or `undefined`.
Returns:
Type
Boolean

true if the arrays are equal, false otherwise.

Example
var array = [1, 2, 3];

array.equals(array);     // -> true
array.equals([1, 2, 3]); // -> true
array.equals([3, 2, 1]); // -> false

get(index) → {*}

Retrieve an item in the array.

Parameters:
Name Type Description
index Number

A zero-based integer indicating which item to retrieve.

Source:
Returns:
Type
*

The item at the specified index.

Example
var array = [1, 2, 3];
array.get(0);  // 1
array.get(1);  // 2
array.get(-1); // 3
array.get(-2); // 2
array.get(5);  // undefined

includes(searchElement, fromIndex) → {Boolean}

Determines if the array includes a certain element.

Parameters:
Name Type Argument Default Description
searchElement *

The element to search for.

fromIndex Number <optional>
0

The index in this array at which to begin the search.

Source:
Returns:
Type
Boolean

true if the item is in the array, false otherwise.

intersect(*arrays) → {Array}

Performs a set intersection on this array and the input array(s).

Parameters:
Name Type Argument Description
*arrays Array <repeatable>

A variable number of arrays or array-like objects.

Source:
Returns:
Type
Array

An array that is the intersection of this array and the input array(s).

Example
[1, 2, 3].intersect([2, 3, 4]); // -> [2, 3]
[1, 2, 3].intersect([101, 2, 50, 1], [2, 1]); // -> [1, 2]

remove(*items) → {Array}

Removes all occurrences of the passed in items from the array if they exist in the array.

Parameters:
Name Type Argument Description
*items * <repeatable>

Items to remove from the array.

Source:
Returns:
Type
Array

A reference to the array (so it's chainable).

Example
var array = [1, 2, 3, 3, 4, 3, 5];
array.remove(1);    // -> [2, 3, 3, 4, 3, 5]
array.remove(3);    // -> [2, 4, 5]
array.remove(2, 5); // -> [4]

union(*arrays) → {Array}

Returns an array containing every distinct item that is in either this array or the input array(s).

Parameters:
Name Type Argument Description
*arrays Array <repeatable>

A variable number of arrays or array-like objects.

Source:
Returns:
Type
Array

An array that is the union of this array and the input array(s).

Example
[1, 2, 3].union([2, 3, 4, 5]); // -> [1, 2, 3, 4, 5]

uniq(isSorted) → {Array}

Returns a duplicate-free clone of the array.

Parameters:
Name Type Argument Default Description
isSorted Boolean <optional>
false

If the input array's contents are sorted and this is set to true, a faster algorithm will be used to create the unique array.

Source:
Returns:
Type
Array
Example
// Unsorted
[4, 2, 3, 2, 1, 4].uniq();     // -> [4, 2, 3, 1]

// Sorted
[1, 2, 2, 3, 4, 4].uniq();     // -> [1, 2, 3, 4]
[1, 2, 2, 3, 4, 4].uniq(true); // -> [1, 2, 3, 4] (but faster than on the previous line)

without(*items) → {Array}

Returns a copy of the current array without any elements from the input parameters.

Parameters:
Name Type Argument Description
*items * <repeatable>

Items to leave out of the returned array.

Source:
Returns:
Type
Array
Example
[1, 2, 3, 4].without(2, 4); // -> [1, 3]