创造新的财产,我有一些JSON数据,看起来像这样,每个对象有三个属性:变换对象的JSON数组,从两个属性值
data = [
{
"country" : "Ireland",
"year" : "2013",
"number" : 45
},
{
"country" : "Ireland",
"year" : "2014",
"number" : 23430
},
{
"country" : "Honduras",
"year" : "2013",
"number" : 1582
},
{
"country" : "Honduras",
"year" : "2014",
"number" : 3458
}
]
我想,这样有改造我的数据每个对象只有两个属性。名为“国家”的房产将保持不变。我想结合其他两个属性,以便“年”的值成为新属性的关键,而“数”的值是新属性的值。因此,新的JSON对象阵列看起来像这样:
newData = [
{
"country" : "Ireland",
"2013" : 45,
"2014" : 23430
},
{
"country" : "Honduras",
"2013" : 1582,
"2014" : 3458
}
]
我该怎么做呢?我做了很多搜索,找不到解决方案。我宁愿使用JavaScript来做到这一点,而不是图书馆。
非常感谢您的帮助! – sprucegoose