June 30, 2025
Explain jQuery.each() method
jQuery.each() method is used to iterate an javascript array or object. It works like a for loop but it have more cleaner syntax. jQuery.each method requires two arguments first is array or object which needs to be iterate, second is function which will be called on each element of array or object element. Example of jQuery.each() method is mentioned below:
jQuery.each() method example
<html>
<head>
<title>Example</title>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
</head>
<body>
<script>
var colors = ["red", "black", "blue", "green"];
$.each(colors , function(index, value) {
console.log(index + ": " + value);
});
</script>
</body>
</html>