Array and object provide $.each() method() for itration.We can iterate or loop over each element in an array or attribute of an object.
Example:
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>to iterating overarrays and objects with jQuery.each</title>
<script src="//code.jquery.com/jquery-1.10.2.js"></script>
<script type="text/javascript">
$(document).ready(function () {
var months = ['office', 'excel', 'outlook', 'powerpoint', 'one note',
'one drive', 'puplisher'];
$.each(months, function (index, value) {
$('#microsoft').append('<li>' + value + '</li>');
});
var days = {
Sunday: 1, Monday: 2, Tuesday: 3, Wednesday: 4,
Thursday: 5, Friday: 6, Saturday: 7
};
$.each(days, function (key, value) {
$('#week').append('<li>' + key + ' (' + value + ')</li>');
});
});
</script>
<style type="text/css">
div {
display: inline-block;
float: left;
color: #fff;
font-size: 18px;
padding-left: 5px;
}
.first {
width: 150px;
height: 200px;
background: red;
}
.second {
width: 200px;
height: 200px;
background: lightgreen;
}
</style>
</head>
<body>
<div class="first" id="microsoft">microsoft products</div>
<div class="second" id="week">week days</div>
</body>
</html>
Output:
Post your comments / questions
Recent Article
- How to fix HAXM is not installed |in Android Studio
- How to fix CMOS Checksum Error in Computer or Laptop | SOLVED
- Reactivating windows after a Hardware change on PC or Laptop
- FIXED: Windows reported that the hardware of your device has changed. Error code :0xc004F211
- "redirect" is not defined pylance("reportUndefinedVariable)
- This action cannot be completed because the file is open in SQL Server(SQLEXPRESS) - FIXED
- Unicode error 'unicodeescape' codec can't decode bytes in position 2-3: truncated UXXXXXXXX escape
- Could not find the 'angular-devkit/build-angular:dev-server' builder's node package | Angular Error
Related Article