Home  >  Article  >  Web Front-end  >  What are the methods of javascript arrays

What are the methods of javascript arrays

coldplay.xixi
coldplay.xixiOriginal
2021-04-08 16:27:575395browse

Javascript array methods include: 1. [isArray()] method is used to determine whether the variable is a js array; 2. [forEach()] method is mainly used to traverse the array; 3. [map() ] method executes the same function on each element in the array to create a new array.

What are the methods of javascript arrays

The operating environment of this tutorial: Windows 7 system, JavaScript version 1.8.5, DELL G3 computer.

Javascript array methods include:

1. isArray() method. This method is mainly used to determine whether the variable is a js array. For example, the following function determines whether fruits is an array and returns true.

What are the methods of javascript arrays

2. forEach() method, this method is mainly used to traverse arrays. For example, let's call the myFunction() function once for each element of the array.

What are the methods of javascript arrays

#3. The map() method is mainly used to create a new array by executing the same function on the elements in each array. For example, the following multiplies each array element by 2 to create a new array numbers2

What are the methods of javascript arrays

4. The filter() method, similar to the map method, also filters each element in the array. Perform the same function on each element and combine the results into a new array.

What are the methods of javascript arrays

#5. The reduce() method mainly executes a function on each element in the array to generate a value. For example, the following finds the sum of array elements.

What are the methods of javascript arrays

6. The every() method is mainly used to check whether each element in the array meets the conditions of the function. If one of them does not meet the conditions, it returns false

What are the methods of javascript arrays

7. IndexOf() access is mainly used to find elements in an array and return the position of the element.

What are the methods of javascript arrays

Related free learning recommendations: javascript(Video)

The above is the detailed content of What are the methods of javascript arrays. 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