我需要一个对象数组映射成这种格式:地图动态关键值
"Brandenburg Gate, Berlin": {latitude: 52.516272, longitude: 13.377722},
"Dortmund U-Tower": {latitude: 51.515, longitude: 7.453619},
"London Eye": {latitude: 51.503333, longitude: -0.119722},
"Kremlin, Moscow": {latitude: 55.751667, longitude: 37.617778},
"Eiffel Tower, Paris": {latitude: 48.8583, longitude: 2.2945},
"Riksdag building, Stockholm": {latitude: 59.3275, longitude: 18.0675},
"Royal Palace, Oslo": {latitude: 59.916911, longitude: 10.727567}
}
在我的源阵列看起来像
{place: "Brandenburg Gate, Berlin", latitude: 52.5, longitude 13.3 }
我无法弄清楚如何使place
成为该阵列的关键。
_.map(a, function (m) {return m.place: {longitude: m.longitude}})
显然是错误的。
你确定这是一个数组?它看起来像JSON – beautifulcoder
@beautifulcoder:绝对不是JSON,以及数据如何被接收/编码与问题无关。 –