请找到我的json数组,我想以下面的格式形成数据数组:
[Sunday.a_count.value,Monday.a_count.value,Tuesday.a_count.value,Wednesday.a_count.value] - 此格式输出将 [0,2,2,3] -
最终,这些值来自星期日a_count,星期一a_count,星期二a_count和星期三a_count。
我无法在javascript中使用json下面的json形成上述格式的数据,如果有人可以帮助实现这一点,那将非常有帮助。
谢谢!
[ {
"day" : "Sunday",
"a_count" : 0,
"b_count" : 2,
"c_count" : 0,
"d_count" : 0
}, {
"day" : "Monday",
"a_count" : 2,
"b_count" : 0,
"c_count" : 0,
"d_count" : 0
}, {
"day" : "Tuesday",
"a_count" : 2,
"b_count" : 0,
"c_count" : 0,
"d_count" : 0
}, {
"day" : "Wednesday",
"a_count" : 3,
"b_count" : 0,
"c_count" : 0,
"d_count" : 0
} ]
答案 0 :(得分:2)
根据我的理解,您希望从a_count
获得价值,您可以使用.map
来实现,就像这样
var data = [ {
"day" : "Sunday",
"a_count" : 0,
"b_count" : 2,
"c_count" : 0,
"d_count" : 0
}, {
"day" : "Monday",
"a_count" : 2,
"b_count" : 0,
"c_count" : 0,
"d_count" : 0
}, {
"day" : "Tuesday",
"a_count" : 2,
"b_count" : 0,
"c_count" : 0,
"d_count" : 0
}, {
"day" : "Wednesday",
"a_count" : 3,
"b_count" : 0,
"c_count" : 0,
"d_count" : 0
} ];
var res = data.map(function (el) {
return el.a_count;
});
console.log(res);