Home  >  Article  >  Web Front-end  >  Summary of JavaScript array operations

Summary of JavaScript array operations

黄舟
黄舟Original
2017-08-04 10:18:541138browse

People who are engaged in the Internet, whether it is the traditional web side or the mobile Internet (webview) side, will deal with JS (JavaScript) to a greater or lesser extent. The following are the common operations and methods of js array (array)

1. Creation of javaScript array

1.JS allows the creation of an array with a variable length , a fixed-length array, or an array with default values.

The declaration or creation method is as follows:

Summary of JavaScript array operations

2. Manipulate the elements in the JS array

1. Assign value : You can access the element at the specified position of the js array through index (subscript) and assign a value to it.

The index (subscript) starts at 0.

The assignable type is: numerical value, character, string or object

The method is as follows:

Summary of JavaScript array operations

#2. Visit. The element at the specified position of the js array can be accessed through index (subscript).

The method is as follows:

Summary of JavaScript array operations

3. Adding array elements

1. The adding method is divided according to the insertion position 3 types: the starting position of the array, the end of the array, or the specified position of the array

Summary of JavaScript array operations

##4. Deletion of array elements

1. There are three types of deletion of array elements: deletion of elements at the beginning of the array, deletion of elements at the end of the array, or deletion of elements of a specified length at a specified position. element.

Summary of JavaScript array operations

5. Interception and merging of array elements

1. Interception of array elements: You can use the built-in function slice(start, [end]) to intercept array elements starting from the start position and ending at the end position.

Summary of JavaScript array operations

2. Merging of array elements: You can use the built-in function concat([item1[, item2[, . . . [ ,itemN]]]]); Connect multiple arrays into one array.

Summary of JavaScript array operations

6. Array sorting

1. Arrays can be sorted by themselves through built-in functions. There are two sorting methods, one is natural sorting and the other is reverse sorting

Summary of JavaScript array operations

7. Other useful built-in functions or properties of JS

1. Get the length of the array (Array). It can be obtained through the length attribute, the format is:

Summary of JavaScript array operations

The above is the detailed content of Summary of JavaScript array operations. 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