AvailabilityJavaScript 1.2; JScript 5.5; ECMAScript v3 Synopsisarray.splice(start, deleteCount, value, ...) Arguments
ReturnsAn array containing the elements, if any, deleted from array. Note, however, that due to a bug, the return value is not always an array in the Netscape implementation of JavaScript 1.2. Descriptionsplice( ) deletes zero or more array elements starting with and including the element start and replaces them with zero or more values specified in the argument list. Array elements that appear after the insertion or deletion are moved as necessary so that they remain contiguous with the rest of the array. Note that, unlike the similarly named slice( ), splice( ) modifies array directly. ExampleThe operation of splice( ) is most easily understood through an example: var a = [1,2,3,4,5,6,7,8] a.splice(4); // Returns [5,6,7,8]; a is [1,2,3,4] a.splice(1,2); // Returns [2,3]; a is [1,4] a.splice(1,1); // Netscape/JavaScript 1.2 returns 4 instead of [4] a.splice(1,0,2,3); // Netscape/JavaScript 1.2 returns undefined instead of [] Bugssplice( ) is supposed to return an array of deleted elements in all cases. However, in Netscape's JavaScript 1.2 interpreter, when a single element is deleted it returns that element rather than an array containing the element. Also, if no elements are deleted, it returns nothing instead of returning an empty array. Netscape implementions of JavaScript emulate this buggy behavior whenever Version 1.2 of the language is explicitly specified. See Also |