ES6数据分组
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; }
赞 (0)