c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
JQuery

How to iterating over arrays and objects with jQuery.each?

| | JQuery

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:

iterating over arrays and objects with jQuery.each