ES6数据分组
程序员文章站
2022-06-27 20:44:52
ItemGroupBy(arr, key) { let newArr = [], types = {}, newItem, i, j, cur; for (i = 0, j = arr.length; i < j; i++) { cur = arr[i]; if (!(cur[key] in typ ......
itemgroupby(arr, key) {
let newarr = [],
types = {},
newitem, i, j, cur;
for (i = 0, j = arr.length; i < j; i++) {
cur = arr[i];
if (!(cur[key] in types)) {
types[cur[key]] = { type: cur[key], data: [] };
newarr.push(types[cur[key]]);
}
types[cur[key]].data.push(cur);
}
return newarr;
}
上一篇: 滚动加载,可视区域判断