标签:asc 技术 highlight java lda ret alt pre for
//把对象数据按照某一个属性进行分类 function sort_pro (data, name) { let c = []; let d = {}; data.forEach(element => { if (!d[element[name]]) { c.push({ [name]: element[name], allData: [element] }); d[element[name]] = element; } else { c.forEach(ele => { if (ele[name] == element[name]) { ele.allData.push(element); } }); } }); return c; }
var data = [
{name:‘张三‘,score:56},
{name:‘张三‘,score:70},
{name:‘李四‘,score:100}
]
sort_pro(data ,‘name‘)
结果:
标签:asc 技术 highlight java lda ret alt pre for
原文地址:https://www.cnblogs.com/wangyunhui/p/11255703.html