728x90
_.groupBy 는 리턴값이 같은것 끼리 array로 묶는다.
data = [
{ registrationDate: "20211201", birthday: "19920102", name:"김동현" }
,{ registrationDate: "20211210", birthday: "19920202", name:"이동현" }
,{ registrationDate: "20211225", birthday: "19920302", name:"박동현" }
,{ registrationDate: "20220102", birthday: "19930102", name:"김동수" }
,{ registrationDate: "20220112", birthday: "19930202", name:"박동수" }
,{ registrationDate: "20220122", birthday: "19930302", name:"이동수" }
,{ registrationDate: "20220122", birthday: "19930302", name:"최동수" }
]
var filterData = _.groupBy(data, function(row){ return (row.birthday.substr(0,3});
filterData = { 1992: Array(3), 1993:(4) };
728x90
'Javascript underscore' 카테고리의 다른 글
[underscore] 언더스코어 정리 (0) | 2021.12.06 |
---|---|
[underscore] groupBy (0) | 2021.12.06 |