JQuery Create Array Object

From CoderLearner
Jump to: navigation, search

Description

Create array object.

Example

<html>
    <head>
        <title>Object</title>
        <script type="text/javascript" src="/js/jquery-1.8.3.js"></script>
    </head>
    <body>
        <script type="text/javascript">
            $().ready(function() {
                var users = [{name: 'bob', age: 24},
                    {name: 'Janny', age: 40},
                    {name: 'Bo', age: 34},
                    {name: 'Thoma', age: 10}];

                //$('#show_text').html(users[1].name);


                for (var i = 0; i < users.length; i++) {
                    var tmp = users[i].name + " is  " + users[i].age + " year old.<br/>";
                    $('#show_text').append(tmp);

                }
            });
        </script>

        <div id="show_text"></div>
    </body>
</html>


Result

bob is 24 year old.
Janny is 40 year old.
Bo is 34 year old.
Thoma is 10 year old.