JS Array 操作~删除数组中某项
JAVASCRIPT:
- Array.prototype.del = function(n) {
- //n表示第几项,从0开始算起。
- if (n < 0)
- return this;
- else
- return this.slice(0, n).concat(this.slice(n + 1, this.length));
- }
- var test = new Array(0, 1, 2, 3, 4, 5);
- test = test.del(3); //从0算起,这里也就是删除第4项。
- alert(test);