Utils.Array Class
Provides array functions
Methods
first
-
xs
Given a array, string or otherwise sequencial object, returns the first item
Parameters:
-
xsString | Array | Array-likeSequencial object
Returns:
First item or null
Example:
import {first} from './utils/array';
first([1, 2, 3, 4]); // -> 1
flatten
-
xs
If given a multidimensional array, flattens it into a single dimension and returns the result
Parameters:
-
xsArrayMultidimensional array
Returns:
Flattened array
Example:
import {flatten} from './utils/array';
flatten([1, 2, [3, [4]]]);
// -> [1, 2, 3, 4]
head
-
xs
Given a array, string or otherwise sequencial object, returns the head item
Parameters:
-
xsString | Array | Array-likeSequencial object
Returns:
List with the head item
Example:
import {head} from './utils/array';
head([1, 2, 3, 4]);
// -> [1]
initial
-
xs
Given a array, string or otherwise sequencial object, returns all items but the last
Parameters:
-
xsString | Array | Array-likeSequencial object
Returns:
List with the initial items
Example:
import {initial} from './utils/array';
initial([1, 2, 3, 4]);
// -> [1, 2, 3]
last
-
xs
Given a array, string or otherwise sequencial object, returns the last item
Parameters:
-
xsString | Array | Array-likeSequencial object
Returns:
Last item or null
Example:
import {last} from './utils/array';
last([1, 2, 3, 4]);
// -> 4
rest
-
xs
Given a array, string or otherwise sequencial object, returns all items but the first
Parameters:
-
xsString | Array | Array-likeSequencial object
Returns:
List with the rest items
Example:
import {rest} from './utils/array';
rest([1, 2, 3, 4]);
// -> [2, 3, 4]
sizeOf
-
xs
Given a enumerable value, counts the number of items the enumerable contains
Parameters:
-
xsString | Array | Array-like | ObjectEnumerable
Returns:
Number of items inside xs
Example:
import {sizeOf} from './utils/array';
sizeOf('hello world'); // -> 11
sizeOf([1, 2, 3]); // -> 3
sizeOf({a: 1, b: 2, c: 3}); // -> 3
tail
-
xs
Given a array, string or otherwise sequencial object, returns the tail item
Parameters:
-
xsString | Array | Array-likeSequencial object
Returns:
List with the tail item
Example:
import {tail} from './utils/array';
tail([1, 2, 3, 4]);
// -> [4]
toArray
-
v
Converts strings, objects and array-like values into real arrays.
Parameters:
-
vString | Array-like | ObjectValue to transform
Returns:
A real array
Example:
import {toArray} from './utils/array';
var nodes = toArray(document.querySelectorAll('div'));
// -> [<div>, <div>, ...]
