Home > Web Front-end > JS Tutorial > body text

Is there any way to get the length of an array in javascript?

青灯夜游
Release: 2021-10-18 18:04:06
Original
21413 people have browsed it

In JavaScript, you can use the length attribute of the array object to get the length of the array. This attribute can set or return the number of elements in the array. You only need to use the "array.length" statement to return the array object. The value of the number of elements, that is, the length value.

Is there any way to get the length of an array in javascript?

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

In JavaScript, if you want to get the length value of an array, you can use the length attribute of the array object.

The role of the length attribute: Set or return the number of elements in the array, that is, the length of the array.

Syntax for returning the length of the array:

array.length
Copy after login

Return value: Numeric value, indicating the number of elements of the array object.

Example:

var arr=[2,6,1,5,22,3,66,12,9];
arr.length;
Copy after login

Is there any way to get the length of an array in javascript?

[Recommended learning: javascript advanced tutorial]

The above is the detailed content of Is there any way to get the length of an array in javascript?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template