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