Javascript methods to change the original array: 1. Push adds something to the array; 2. Pop cuts out the last element of the array; 3. Unshit adds an element before the first element of the array; 4. , shit deletes from the first element in front of the array.
The operating environment of this tutorial: windows10 system, javascript1.8.5, this article is applicable to all brands of computers.
Related free learning recommendations: JavaScript (video)
Javascript method to change the original array:
1, push
: Add something to the array: add
2, pop
from the last element of the array : Cut out the last element of the array. Pop does not need to pass parameters when executing.
3, unshit
: It goes to the first element of the array. Add element
4, shit
: Delete
## from the first element in front of the array
reverse: Reverse the direction of the element
splice: arr.splice(from Start with a few numbers, intercept the length, and add new data at the notch). The latter data can be added or not. You can add countless data
var arr = [1,1,2,2,3,3];
sort: Sort the original array
var arr = [1,3,4,0,-1,9];
The above is the detailed content of How to change the original array in javascript. For more information, please follow other related articles on the PHP Chinese website!