TXXT

新手坚持写代码,最后一定会成为老手

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

数组插入元素push
Array.prototype.push=function(){
for(var i=0;i<arguments.length;i++){
this[this.length]=arguments[i];
}

数组删除第一个元素shift
Array.prototype.shift=function(){
var oArr=[]
for(i=this.length-1;i>0;i--){
oArr[i-1]=this[i];
}
return oArr;
}
数组删除指定序列元素splice
Array.prototype.splice=function(){
var oArr=[]
for(i=0;i<this.length;i++){
if(i<arguments[0]){
oArr.push(this[i]);
}else if(i>arguments[0]+arguments[1]-1){
oArr.push(this[i]);
}
}
return oArr;
}

posted on 2016-09-03 09:45  TXXT  阅读(201)  评论(0编辑  收藏  举报