Home  >  Article  >  Web Front-end  >  How to change the original array in javascript

How to change the original array in javascript

coldplay.xixi
coldplay.xixiOriginal
2020-11-18 16:11:126993browse

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.

How to change the original array in javascript

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

How to change the original array in javascript

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.

How to change the original array in javascript

3, unshit: It goes to the first element of the array. Add element

How to change the original array in javascript

4, shit: Delete

How to change the original array in javascript## from the first element in front of the array

#5,

reverse: Reverse the direction of the element

How to change the original array in javascript

6,

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

or you can start intercepting from a negative number. The negative number is the last number of the array. Several bits, but only the length of one data can be intercepted

var arr = [1,1,2,2,3,3];

Define an array, starting from the first position of the array, intercept the length of one unit, and add 0, 0, 0 from the cutout

How to change the original array in javascript

7,

sort: Sort the original array

var arr = [1,3,4,0,-1,9];

How to change the original array in javascript

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn