Thursday, 29 June 2017

How to make a list of Object in JavaScript



How to make a list of Object  in JavaScript


<script>
 var cityObject= GetCityObjectArray();
for(var i=0;i<cityObject.length;i++)
{    
       alert(cityObject[i].Name);
}
 function GetCityObjectArray()
 {
        var cities = new Array();    
        for(var i=0;i<=10;i++)
        {  var city = {};
           city.Name = i;
           city.Population = i;
           cities.push(city);
        }
       console.log(cities);
       return cities;
  }
</script>



No comments:

Post a Comment