The "$.each()" method can be used in jquery to loop through the array elements, and then output the array elements one by one in the loop body; the syntax "$.each(arr,function(index,value){ console.log(index ":" value);})".
Related recommendations: "jQuery Video Tutorial"
The operating environment of this tutorial: windows7 system, jquery version 2.2.4 , this method is suitable for all brands of computers.
In jquery, you can use the $.each() method to loop through array elements to output all array elements.
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>JQuery循环遍历输出数组元素示例</title> <script src="https://cdn.staticfile.org/jquery/2.2.4/jquery.min.js"></script> </head> <body> <script> $(document).ready(function(){ var arr=["Apple", "Banana", "Orange", "Mango", "Pineapple"]; $.each(arr, function(index, value){ console.log(index + ": " + value + '<br>'); }); }); </script> </body> </html>
$.each() method has two parameters. The first parameter is the name of the array to be looped, and the second parameter is a method.
Here we define an arr array, and then pass an array index (index) and corresponding array value (value) to each callback in this method, and then loop out the specified array through the append() method The result of the value is printed.
The results are as follows:
For more programming-related knowledge, please visit: Programming Video Course! !
The above is the detailed content of How to output the value of an array in jquery?. For more information, please follow other related articles on the PHP Chinese website!