Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

splice Method (Array) (JavaScript)

Removes elements from an array and, if necessary, inserts new elements in their place, returning the deleted elements.

arrayObj.splice(start, deleteCount, [item1[, item2[, . . . [,itemN]]]])


Required. An Array object.


Required. The zero-based location in the array from which to start removing elements.


Required. The number of elements to remove.

item1, item2,. . ., itemN

Optional. Elements to insert into the array in place of the deleted elements.

The splice method modifies arrayObj by removing the specified number of elements from position start and inserting new elements. The deleted elements are returned as a new Array object.

The following code shows how to use the splice method.

var arr = new Array("4", "11", "2", "10", "3", "1");
arr.splice(2, 2, "21", "31");

// Output: 4,11,21,31,3,1

Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards, Internet Explorer 10 standards, Internet Explorer 11 standards. Also supported Store apps (Windows 8 and Windows Phone 8.1). See Version Information.

© 2015 Microsoft