JavaScript: The Definitive Guide, Sixth Editio javaScript权威指南(第6版) pdf 文字版-文字版, javascript电子书, 和javascript 有关的电子书:

Array.splice()

// An ordering function for a numerical sort function numberorder(a, b) { return a - b; } a = new Array(33, 4, 1111, 222); a.sort(); // Alphabetical sort: 1111, 222, 33, 4 a.sort(numberorder); // Numerical sort: 4, 33, 222, 1111


Array.splice()

insert, remove, or replace array elements

Synopsis

array.splice(start, deleteCount, value, ...)

Arguments

start

The array element at which the insertion and/or deletion is to begin.

Core JavaScript Reference | 737

Array.toLocaleString()

deleteCount The number of elements, starting with and including start, to be deleted from array. Specify 0 to insert elements without deleting any.

value, ... Zero or more values to be inserted into array, beginning at the index specified by start.

Returns

An array containing the elements, if any, deleted from array.

Description

splice() 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.

Example

The operation of splice() is most easily understood through an example:

var a = [1,2,3,4,5,6,7,8] a.splice(1,2); // Returns [2,3]; a is [1,4] a.splice(1,1); // Returns [4]; a is [1] a.splice(1,0,2,3); // Returns []; a is [1 2 3]

See Also

Array.slice()

欢迎转载,转载请注明来自一手册:http://yishouce.com/book/1/28129.html
友情链接It题库(ittiku.com)| 版权归yishouce.com所有| 友链等可联系 admin#yishouce.com|粤ICP备16001685号-1