Home > Web Front-end > JS Tutorial > How to query how many array elements there are in jquery

How to query how many array elements there are in jquery

WBOY
Release: 2021-11-30 11:12:36
Original
3132 people have browsed it

In jquery, you can use the length attribute to query how many array elements there are. The length attribute can count the number of array elements and return it. The syntax is "array element object.length".

How to query how many array elements there are in jquery

The operating environment of this tutorial: windows7 system, jquery3.2.1 version, Dell G3 computer.

jquery query has several array elements

In jquery, you can use it directly length property to get the number of elements in the array.

The example is as follows:

1. Create a new html file, named test.html, to explain how jquery finds the number of array elements. Create a button button and set its id to test, which will be used to trigger the calculation of the number of array elements below.

In the js tag, execute the function method through the ready() method when the page is loaded.

How to query how many array elements there are in jquery

2. In the function method, obtain the button object through the id, bind the click event to it, and when the button is clicked, execute its function method.

In the function method, create an array and save it in the arr variable, then use the length attribute to obtain the current number of array elements, and use the alert() method to output.

How to query how many array elements there are in jquery

Open the test.html file in the browser, click the button to view the results.

How to query how many array elements there are in jquery

Summary:

1. Create a button button to trigger the calculation of the number of array elements below.

2. In js, create an array and save it in the arr variable, and then use the length attribute to get the current number of array elements.

Recommended related video tutorials: jQuery video tutorial

The above is the detailed content of How to query how many array elements there are in jquery. 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