【JavaScript基礎】-用數組模擬實現shift方法

問題需求:
刪除數組第一個元素,不能使用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]
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章