The method of operating an array js

1. arr.push () length of the array elements of the array from the last added, the return value is added

let arr = [3,2,1]
arr.push(9)
console.log(arr) // [3,2,1,9]

2. arr.pop () removed the last of the array from an element can only delete one, the return value is removed elements

let arr = [1,2,3,4]
console.log(arr.pop()) // 4
console.log(arr) // [1,2,3]

3. arr.shift () array delete an element from the front, one can only delete one, the return value is removed elements

let arr = [1,2,3,4]
console.log(arr.shift()) // 1
console.log(arr) // [2,3,4]

 

Guess you like

Origin www.cnblogs.com/beline/p/11330187.html