-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathimp1.js
More file actions
38 lines (34 loc) · 656 Bytes
/
imp1.js
File metadata and controls
38 lines (34 loc) · 656 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//you have to group data from property that is received as an argument
var students = [{
name: "ram",
class: 2,
house: 'blue'
}, {
name: "shyam",
class: 5,
house: 'green'
}, {
name: "ramesh",
class: 2,
house: 'green'
}, {
name: "sita",
class: 3,
house: 'blue'
}, {
name: "gita",
class: 2,
house: 'green'
}];
function groupBy(arr, property) {
var group = {};
students.forEach(object => {
if(!group[object[property]] ){
group[object[property]]=[object]
}else{
group[object[property]].push(object)
}
});
console.log(group)
}
groupBy(students, 'class');