我有一個JavaScript數組這樣JavaScript的數組二維數組
var myArr = [
{
"Year":"2015",
"Month":"January",
"Value":"15.8",
"District":"Anuradhapura",
"type":"Rainfall"
},
{
"Year":"2015",
"Month":"January",
"Value":"31.1",
"District":"Anuradhapura",
"type":"Temparature"
},
{
"Year":"2015",
"Month":"January",
"Value":"4",
"District":"Anuradhapura",
"type":"Wind"
},
{
"Year":"2015",
"Month":"January",
"Value":"69",
"District":"Anuradhapura",
"type":"Humidity"
}
]
我需要的是把type
和Value
數據爲2維數組。我的最終結果應該是這樣的;
var data = [
[
"Rainfall",
158
],
[
"Temparature",
31.1
],
[
"Wind",
4
],
[
"Humidity",
69
]
]
注意myArr
結果我從後端服務,該數組的長度讓我可以動態改變。我怎樣才能做到這一點。感謝
雖然你將不得不增加仍轉換x.Value一個數值。 :) –
@winner_joiner感謝 –