我需要一個對象數組映射成這種格式:地圖動態關鍵值
"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,以及數據如何被接收/編碼與問題無關。 –