JQuery Create Array

From CoderLearner
Jump to: navigation, search

Description

Create Array.

Syntax


var aa= [];
var aa1= [4,5,4,44];


Example

<html>
    <head>
        <title>Object</title>
        <script type="text/javascript" src="/js/jquery-1.8.3.js"></script>
        <script type="text/javascript">
            $().ready(function() {
              var dtt= [41,54,52,42,5];
              
              for(var i=0; i < dtt.length; i++) {
                  $("#show_text").append(dtt[i]+ "<br/>");
              }
            });
        </script>
    </head>
    <body>
        <div id="show_text"></div>
    </body>
</html>

Result

41
54
52
42
5

Example 2

var dtt = [41, 54, 52, 42, 5];

$.each(dtt, function(index, value) {
        $("#show_text").append(index + " -- " +value + "<br/>");
});

Result

0 -- 41
1 -- 54
2 -- 52
3 -- 42
4 -- 5