Hosting Solutions
mobile_logo Table of Contents
seal_frontseal_back

splice

The splice() method of the Array object removes array elements and optionally replaces them.

Syntaxarray.splice( start, deleteCount , ...items )

Parameters

start Specify the index position to start the splice in the array. deleteCount Specify the amount of elements to remove relative to the start parameter. ...items ( optional ) Specify one or more replacement values separated by commas.

Examples

var arr = ["a","b","c","d","e"]; /* starting from index 2, remove 2 elements */ var result = arr.splice( 2, 2 ); alert( result ); /* c,d */ alert( arr ); /* a,b,e */ var arr = ["a","b","c","d","e"]; /* At index 2, remove 2 items and specify replacement items */ var result = arr.splice( 2, 2, "x", "y" ); alert( result ); /* c,d */ alert( arr ); /* a,b,x,y,e */

JavaScript

Methods

addEventListeneralertaveragebackblurconcatcreatedecodeURIdecodeURIComponentencodeURIencodeURIComponentevaleveryfilterforwardgoisArrayisFiniteisNaNjoinparseFloatparseIntpoppushpushStatereducereplaceStatereverseshiftshuffleslicesomesortspliceunshiftwrite