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".
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.
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.
Open the test.html file in the browser, click the button to view the results.
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!