Categories

jQuery.unsplice()

Categories: Utilities

jQuery.unsplice( target, insert, [ index ] )Returns: Array

Plugin: jQuery.array

Description: Add an array into an array at a specified position without overwrite existing items.

  • jQuery.unsplice( target, insert, [ index ] )

    version added: 1.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 jQuery.unsplice() is an inverted method to the native javascript .splice().

If no index position specified, the array will insert at the end of the target array. The The jQuery.unsplice() works with array-like objects also.

  • Insert value at a specified position in an array.

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

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