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

How to output the value of an array in jquery?

青灯夜游
Release: 2020-11-30 09:41:45
Original
3623 people have browsed it

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);})".

How to output the value of an array in jquery?

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 + &#39;<br>&#39;);
            });
        });
    </script>
</body>
</html>
Copy after login

$.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:

How to output the value of an array in jquery?

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!

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