Last active
January 31, 2019 19:37
-
-
Save talha08/040c65946b9a87bcc11d4867313c7ec8 to your computer and use it in GitHub Desktop.
JS Bin// source https://jsbin.com/xifegud
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let courses = [ | |
{ | |
"title":"ttile 1", | |
"id":"1", | |
"course_cat":"introduction" | |
}, | |
{ | |
"title":"title 2", | |
"id":"2", | |
"course_cat":null | |
}, | |
{ | |
"title":"blabla 1", | |
"id":"3", | |
"course_cat":"test" | |
}, | |
{ | |
"title":"blabla 2", | |
"id":"4", | |
"course_cat":null | |
} | |
]; | |
let grouped = courses.reduce((allCourses, course) => { | |
allCourses[course.course_cat] = [...allCourses[course.course_cat] || [], course]; | |
return allCourses; | |
}, {}); | |
console.log(grouped); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment