The value of the array can be obtained in jquery. Obtaining method: 1. Use the each() method to traverse the specified array, the syntax is "$.each (the array to be traversed, specify the function for loop execution)"; 2. Use "append(value) in the specified loop function )" to get the value of the array.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
In jquery, traverse the array through the each() method to get the value in the array
Create a new html file and name it It is test.html, used to explain jquery traversing an array and obtaining the values in the array.
Introduce the jquery.min.js library file and successfully load the file before you can use the methods in jquery. Create a module using div and set its id to output, which is used to output the values in the array within the div.
In the js tag, define a myArray array variable. There are three values in the array, namely "Athens", "Belgrade", and "Cairo".
Use the $.each() method to traverse the myArray array. The first parameter in this method is the array variable, and the second parameter is the function method, where index is the array index and value is the value of the array.
Get the div object through id(output), and use the append() method to output the array value on the page in the form of a paragraph.
Open the test.html file in the browser to view the results.
Summary:
1. Create a test.html file.
2. Create a module using div within the file.
3. In the js tag, define a myArray array variable with three values in the array.
4. In the js tag, use the $.each() method to traverse the myArray array, obtain the div object, and use the append() method to output the value of the array on the page in the form of a paragraph.
Notes
$.each() method’s first parameter is an array, and its second parameter is a function method.
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of Can jquery get the value of an array?. For more information, please follow other related articles on the PHP Chinese website!