- reverse
Array.prototype.rev = function () {
var later = this.length - 1,
temp;
for (let i = 0; i < this.length; i++) {
temp = this[i];
this[i] = this[later];
this[later] = temp;
if (i == later || later - i == 1) {
break
}
later--;
}
return this
}
var arr = [8, 6, 3, 2, 9, 5, 7, 1, 4]
console.log(arr.rev())
- push
Array.prototype.Push = function () {
for (var i = 0; i < arguments.length; i++) {
this[this.length] = arguments[i]
}
return this.length
}
var arr = [8, 6, 3, 2, 9, 5, 7, 1, 4]
console.log(arr.Push(555, 77))
console.log(arr)
- pop
Array.prototype.Pop = function () {
var temp = this[this.length - 1]
this.length = this.length - 1;
return temp
}
var arr = [8, 6, 3, 2, 9, 5, 7, 1, 4]
console.log(arr.Pop())
console.log(arr)
- unshift
Array.prototype.unShift = function () {
for (let i = 0; i < arguments.length; i++) {
var later = this.length
for (let index = 0; index < this.length; index++) {
this[later] = this[later - 1]
later--
}
this[0] = arguments[i]
}
return this.length
}
var arr = [8, 6, 3, 2, 9, 5, 7, 1, 4]
console.log(arr.unShift('ssss', 111))
console.log(arr)
- shift
Array.prototype.Shift = function () {
var first = this[0];
for (let index = 0; index < this.length; index++) {
this[index] = this[index + 1]
}
this.length--
return first
}
var arr = [8, 6, 3, 2, 9, 5, 7, 1, 4]
console.log(arr.Shift())
console.log(arr)