-4

我从后面获取数据并将这些数据分配给 javascript var

 var data={"Hunt_Valley": {"code": "HV", "latidue": "39.4900013", "longitude": "-76.6585074"}, "Mexico City": {"code": "MEX", "latidue": "19.4326077", "longitude": "-99.133208"}, "Kiev": {"code": "KBP", "latidue": "50.4501", "longitude": "30.5234"}}

我想迭代这些数据并将每个数据分配给 var 并生成数组,这样数组就会像

           images: [
                    {title:"Hunt_Valley", latitude:39.4900013, longitude:-76.6585074},
                     {title:"Mexico City", latitude:19.4326077, longitude:-99.133208},
                    {title:"Kiev", latitude:50.4501, longitude:30.5234},

迭代这个字符串的方法是什么。

提前谢谢你

4

1 回答 1

2
var result = { images: [] };
for (var city in data) {
    result.images.push( {
        title: city,
        latitude: data[city].latitude,
        longitude: date[city].longitude
    });
}
于 2013-07-02T01:26:58.097 回答