有原始JSON数据如下:
"basic_data": {
"2016-03-24": {
"view_total": 17,
"share_total": 0,
"like_total": 1,
"post_total": 2,
"favorite_total": 1,
"comment_total": 1
},
"2016-03-25": {
"view_total": 10,
"share_total": 0,
"like_total": 0,
"post_total": 58,
"favorite_total": 1,
"comment_total": 0
},
"2016-03-26": {
"view_total": 0,
"share_total": 0,
"like_total": 0,
"post_total": 0,
"favorite_total": 0,
"comment_total": 0
},
"2016-03-27": {
"view_total": 0,
"share_total": 0,
"like_total": 0,
"post_total": 0,
"favorite_total": 0,
"comment_total": 0
},
"2016-03-28": {
"view_total": 0,
"share_total": 0,
"like_total": 0,
"post_total": 0,
"favorite_total": 0,
"comment_total": 0
},
"2016-03-29": {
"view_total": 11,
"share_total": 0,
"like_total": 0,
"post_total": 42,
"favorite_total": 0,
"comment_total": 0
},
"2016-03-30": {
"view_total": 4,
"share_total": 0,
"like_total": 0,
"post_total": 3,
"favorite_total": 0,
"comment_total": 0
}
}
`如何使用原生或者lodash等工具提取如下数据
全选复制放进笔记{
view_total: [17, 10, 0, 0, 0, 11, 4]
}`
lodash版:
var data = _.reduce(basic_data, (result, value) => {
result.view_total.push(value.view_total);
return result;
}, {
view_total: []
});
js版:
var data = {
view_total: Object.keys(basic_data).map(v => {
return basic_data[v].view_total;
})
};
console.log(data);
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。