Categories

ep.insert()

Categories: Utilities

ep.insert( target, insert, [ index ] )

Plugin: ep.core

Description: Add value(s) to an array or array-like object at a specified position without overwrite existing items.

  • ep.insert( target, insert, [ index ] )

    version added: 6.11.0

    target   An array or array-like object to extend with values.

    insert   An array containing additional properties to add.

    index   A zero index position to insert.

The ep.insert() is an inverted method to the native javascript .splice().

  • Insert value at a specified position in an array.

    Code:
    var target = [ 'bar', 'ba', 'banana' ];
    
    ep.insert( target, [ 'strawberry', 'apple' ], 2 );
    
    Results:
    [ 'bar', 'ba', 'strawberry', 'apple', 'banana' ]
    
    
  • Insert value without specified position.

    Code:
    var target = [ 'bar', 'ba', 'banana' ];
    
    ep.insert( target, [ 'strawberry', 'apple' ] );
    
    Results:
    [ 'bar', 'ba', 'banana', 'strawberry', 'apple' ]