We use cookies to make our website more effective. By using our website you agree to our privacy policy.

Namespace: arrays


arrays.js is part of Aloha Editor project http://www.alohaeditor.org

Aloha Editor ● JavaScript Content Editing Library
Copyright (c) 2010-2015 Gentics Software GmbH, Vienna, Austria.
Contributors http://www.alohaeditor.org/docs/contributing.html



Coerces the given object (NodeList, arguments) to an array.

This implementation works on modern browsers and IE >= 9. For IE
< 9 a shim can be used, available here:
Name Type Description
arrayLikeObject *

contains(xs, x){boolean}

Returns true if the given Array `xs` contains the value `x`.
Name Type Description
xs Array
x * A value to search for in the given array.
of argument `x` is an element of the set `xs`.

difference(xs, zs){Array}

Returns the relative difference of array `zs` in `xs`:
All items in the array `xs` that are not contained in array `zs`.
Name Type Description
xs Array
zs Array
difference of the sets `xs` and `zs`.

equal(a, b, equalFn){boolean}

Does a shallow compare of two arrays.
Name Type Description
a Array An array to compare.
b Array A second array to compare with `a`.
equalFn function A custom comparison function that accepts two values a and b from the given arrays and returns true or false for equal and not equal respectively. If no equalFn is provided, the algorithm will use the strict equals operator.
if all items in a and b are equal, false if not.

intersect(xs, zs){Array}

Returns all items in the array `xs` that are also contained in array
Name Type Description
xs Array
zs Array
intersection of the sets `xs` and `zs`.
Returns true if the given value is an array.


Returns the last item in the given Array.
Name Type Description
xs Array
item in xs, or null if the given array is empty.

mapcat(xs, fn){Array.<*>}

Like Array.prototype.map() except expects the given function to return
arrays which will be concatenated together into the resulting array.

Related to partition() in the sense that
mapcat(partition(xs, n), identity) == xs.

Don't use Array.prototype.concat.apply():
"The consequences of applying a function with too many arguments
(think more than tens of thousands of arguments) vary across
engines (JavaScriptCore has hard-coded argument limit of 65536),
because the limit (indeed even the nature of any
excessively-large-stack behavior) is unspecified. "
Name Type Description
xs Array.<*>
fn function

partition(xs, n){Array.<Array.<*>>}

Partitions the given array xs into an array of arrays where each
nested array is a subsequence of xs of length n.

See mapcat().
Name Type Description
xs Array.<*>
n number


This function is missing documentation.
  • Complete documentation.

some(xs, pred){*}

Similar to
Except, instead of returning true, returns the first value in the array
for which the `pred` returns true.
Name Type Description
xs Array.<*>
pred function
of xs

someIndex(xs, pred){*}

Similar to some(), except that it returns an index into the given array
for the first element for which `pred` returns true.

If none return true, -1 is returned.
Name Type Description
xs Array.<*>
pred function

split(list, predicate){Array.<Array.<*>>}

Splits the list into two parts using the given predicate.

The first element will be the "prefix," containing all elements of `list` before
the element that returns true for the predicate.

The second element is equal to dropWhile(list).
Name Type Description
list Array.<*>
predicate function
prefix and suffix of `list`


Creates a new array that contains a unique list of entries
created from the old array. Example:
[1, 2, 2, 3, 2, 4] => [1, 2, 3, 4]
Name Type Description
arr Array.<*>
comments powered by Disqus