JSON数据分组

function GroupBy(arr,key) {
        var obj = {};
        for (let i = 0; i 

例如:

var data=[{
    "ID": "1",
    "Name": "张三",
    "Gender": "男",
    "Birthday": "2020-03-24 00:00:00"
}, {
    "ID": "2",
    "Name": "李四",
    "Gender": "男",
    "Birthday": "2020-03-23 00:00:00"
}, {
    "ID": "3",
    "Name": "王五",
    "Gender": "男",
    "Birthday": "2020-03-20 00:00:00"
}, {
    "ID": "4",
    "Name": "赵六",
    "Gender": "男",
    "Birthday": "2020-03-28 00:00:00"
}, {
    "ID": "5",
    "Name": "田七",
    "Gender": "女",
    "Birthday": "2020-03-25 00:00:00"
}];
console.log(GroupBy(data,"Gender"))
//输出{男: Array(4), 女: Array(1)}

你可能感兴趣的:(JSON数据分组)