在数组开头插入元素
Array.prototype.insertFirstPosition = function(value){ for(let i = this.length;i > 0;i--){ this[i] = this[i-1] } this[0] = value }
从数组开头删除元素
Array.prototype.delUndefined = function(arr){ let newArr = [] for(let i = 0;i < arr.length;i++){ if(arr[i] !== undefined){ newArr.push(arr[i]) } } return newArr } Array.prototype.removeFirstPosition = function(){ for(let i = 0;i < this.length;i++){ this[i] = this[i+1] } return this.delUndefined(this) }