問題需求:
刪除數組第一個元素,不能使用shift方法
問題解決:
Array.prototype.dropFirstElement=function(){
for(let i=0;i<this.length;i++){
this[i]=this[i+1];
//簡單元素位置左移
}
this.length--;
return this;
}
const nums=[3,4,5,6,7];
nums.dropFirstElement();
console.log(nums);//返回[4,5,6,7]