Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js array set value at index

Array.prototype.insert = function ( index, ...items ) {
    this.splice( index, 0, ...items );
};

//then

var arr = [ 'A', 'B', 'E' ];
arr.insert(2, 'C', 'D');

// => arr == [ 'A', 'B', 'C', 'D', 'E' ]
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #js #array #set #index
ADD COMMENT
Topic
Name
7+7 =