Wednesday 19 March 2014

Storing and Displaying of Objects in Arrays in Javascript

Storing and Displaying of Objects in Arrays in Javascript


<!DOCTYPE html>
<html>
<body>
 
<script>
 
var follower2= {
                                firstname: 'John',
                                designation: "Consultant",
                                location: "Sydney, Australia",
                                serviceline: "MS",
                                count: 5
                                };
 
//document.write( 'Name of Follower: '+ follower2.firstname + "<br\>" + 'Designation: ' +follower2.designation + "<br\>" + 'Location: ' + follower2.location + "<br\>" + 'ServiceLine: ' + follower2.serviceline + "<br\>" + 'Followers Count: ' + follower2.count + "<br/>");
 
var follower3= {
                                firstname: "Peter",
                                designation: "Consultant",
                                location: "Sydney, Australia",
                                serviceline: "MS"
                                };
 
var follower4= {
                                firstname: "David",
                                designation: "Consultant",
                                location: "Sydney, Australia",
                                serviceline: "MS"
                                };
 
 
var i;
var myfollowers = new Array();
 
myfollowers.push(follower2);
myfollowers.push(follower3);
myfollowers.push(follower4);
 
 
for (i=0;i<myfollowers.length;i++)
{
 
document.write(i + "<br>");
 
document.write(myfollowers[i].firstname + "<br>");
document.write(myfollowers[i].designation + "<br>");
document.write(myfollowers[i].location + "<br>");
document.write(myfollowers[i].serviceline + "<br>");
 
document.write("no. of of followers: " + myfollowers.length + "<br>");
 
}
 
 
</script>
 
</body>
</html>



No comments:

Post a Comment