CKEDITOR.tools.array
The namespace with helper functions and polyfills for arrays.
Filtering
Methods
-
every( array, fn, [ thisArg ] ) → Boolean
since 4.8.0
Tests whether all elements in an array pass the test implemented by the provided function. Returns
true
if the provided array is empty.var every = this.array.every( [ 11, 22, 33, 44 ], function( value ) { return value > 10; } ); console.log( every ); // Logs: true
Parameters
array : Array
fn : Function
A function that gets called with each
array
item.Propertiesvalue : Mixed
The currently iterated array value.
index : Number
The index of the currently iterated value in an array.
array : Array
The original array passed as the
array
variable.
[ thisArg ] : Mixed
A context object for
fn
.Defaults to
undefined
Returns
Boolean
Information whether all elements pass the test.
-
filter( array, fn, [ thisArg ] ) → Array
Returns a copy of
array
filtered using thefn
function. Any elements that thefn
will returnfalse
for will get removed from the returned array.var filtered = this.array.filter( [ 0, 1, 2, 3 ], function( value ) { // Leave only values equal or greater than 2. return value >= 2; } ); console.log( filtered ); // Logs: [ 2, 3 ]
Parameters
array : Array
fn : Function
A function that gets called with each
array
item. Any item thatfn
returned afalse
-alike value for will be filtered out of thearray
.Propertiesvalue : Mixed
The currently iterated array value.
index : Number
The index of the currently iterated value in an array.
array : Array
The original array passed as the
array
variable.
[ thisArg ] : Mixed
A context object for
fn
.Defaults to
undefined
Returns
Array
The filtered array.
-
forEach( array, fn, [ thisArg ] )
Iterates over every element in the
array
.Parameters
array : Array
An array to be iterated over.
fn : Function
The function called for every
array
element.Propertiesvalue : Mixed
The currently iterated array value.
index : Number
The index of the currently iterated value in an array.
array : Array
The original array passed as an
array
variable.
[ thisArg ] : Mixed
The context object for
fn
.Defaults to
undefined
-
indexOf( array, value ) → Number
Returns the index of an element in an array.
var letters = [ 'a', 'b', 0, 'c', false ]; alert( CKEDITOR.tools.indexOf( letters, '0' ) ); // -1 because 0 !== '0' alert( CKEDITOR.tools.indexOf( letters, false ) ); // 4 because 0 !== false
Parameters
array : Array
The array to be searched.
value : Object | Function
The element to be found. This can be an evaluation function which receives a single parameter call for each entry in the array, returning
true
if the entry matches.
Returns
Number
The (zero-based) index of the first entry that matches the entry, or
-1
if not found.
-
isArray( object ) → Boolean
Checks if an object is an Array.
alert( CKEDITOR.tools.isArray( [] ) ); // true alert( CKEDITOR.tools.isArray( 'Test' ) ); // false
Parameters
object : Object
The object to be checked.
Returns
Boolean
true
if the object is an Array, otherwisefalse
.
-
map( array, fn, [ thisArg ] ) → Array
since 4.6.2
Applies a function to each element of an array and returns the array of results in the same order. Note the order of the parameters.
Parameters
array : Array
An array of elements that
fn
is applied on.fn : Function
A function with the signature
a -> b
.[ thisArg ] : Mixed
The context object for
fn
.Defaults to
undefined
Returns
Array
An array of mapped elements.
-
reduce( array, fn, initial, [ thisArg ] ) → Mixed
since 4.6.2
Applies a function against each value in an array storing the result in an accumulator passed to the next iteration. Note the order of the parameters.
Parameters
array : Array
An array of elements that
fn
is applied on.fn : Function
A function with the signature
(accumulator, a, index, array) -> b
.initial : Mixed
Initial value of the accumulator.
[ thisArg ] : Mixed
The context object for
fn
.Defaults to
undefined
Returns
Mixed
The final value of the accumulator.