unshift()
仿写push() 也类似
//数组的头部插入元素 ,仿写 unshift()
Array.prototype.unshift123 = function(){
var len = arguments.length;
for(var i = this.length -1 + len ; i>= len-1;i--){
this[i]= this[i- len];
}
for(var i = 0;i<len;i++){
this[i]=arguments[i]
}
return this.length;
}
// 例子
var arr = [1,2,3];
console.log(arr.unshift123(4,5,6));
console.log(arr);