CKEditor 4 Documentation

CKEDITOR.tools.array

Files

The namespace with helper functions and polyfills for arrays.

Available since: 4.6.1

Defined By

Methods

CKEDITOR.tools.array
view source
( array, fn, [thisArg] ) : Array
Returns a copy of array filtered using the fn function. ...

Returns a copy of array filtered using the fn function. Any elements that the fn will return false 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 that fn returned a false-alike value for will be filtered out of the array.

    Parameters

    • value : 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 (optional)

    A context object for fn.

    Defaults to: undefined

Returns

  • Array

    The filtered array.

CKEDITOR.tools.array
view source
( array, fn, [thisArg] )
Iterates over every element in the array. ...

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.

    Parameters

    • value : 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 (optional)

    The context object for fn.

    Defaults to: undefined

CKEDITOR.tools.array
view source
( array, value ) : Number
Returns the index of an element in an array. ...

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.

CKEDITOR.tools.array
view source
( object ) : Boolean
Checks if an object is an Array. ...

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, otherwise false.

CKEDITOR.tools.array
view source
( array, fn, [thisArg] ) : Array
Applies a function to each element of an array and returns the array of results in the same order. ...

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.

Available since: 4.6.2

Parameters

  • array : Array

    An array of elements that fn is applied on.

  • fn : Function

    A function with the signature a -> b.

  • thisArg : Mixed (optional)

    The context object for fn.

    Defaults to: undefined

Returns

  • Array

    An array of mapped elements.

CKEDITOR.tools.array
view source
( array, fn, initial, [thisArg] ) : Mixed
Applies a function against each value in an array storing the result in an accumulator passed to the next iteration. ...

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.

Available since: 4.6.2

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 (optional)

    The context object for fn.

    Defaults to: undefined

Returns

  • Mixed

    The final value of the accumulator.