English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Some Methods of Array (Summary)

Overview of array object properties and methods:

1> arr.push() adds the parameters to the end of the array, and returns the length of the new array

2> arr.unshift() adds the parameters to the beginning of the array, and returns the length of the new array

3> arr.shift() deletes the first element of the array, and returns the deleted number

4> arr.pop() deletes the last element of the array, and returns the deleted number

5> arr.concat() merges the numbers in the parameters into the end of the original array, does not change the original array, and returns a new array

6> arr.reverse() reverses the array, which changes the original array

7> arr.sort() defines the sorting method of the array
arr.sort(function (a,b){
return a-b;
});

If a-b, then sort from small to large; if b-a, then sort from large to small

8> arr.slice(startIndex, endIndex) slices the array, does not change the original array, and returns a new array

Start from the startIndex index and end at the endIndex index. The startIndex can be taken, and the endIndex cannot be taken.

If the endIndex parameter is not written, it defaults to the end.

9> arr.splice() deletes the array, which will change the original array

When there are two parameters, the first is the starting position of the array to be deleted, and the second is the number of deletions, starting from the starting position.

When there are three or more parameters, the third and subsequent parameters will be added to the front of the array.

10> arr.join() concatenates the array into a string with the parameters passed in, without changing the original array.

11> arr.indexOf() returns the index value if a match is found, or returns if not found-1

This article summarizes some methods of the array Array, which is all the content that the editor shares with everyone. I hope it can provide a reference for everyone, and I also hope everyone will support the Shouting Tutorial.