Created
October 24, 2011 14:20
-
-
Save fatihacet/1309145 to your computer and use it in GitHub Desktop.
Groups given object by a key
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
var events = data.events; | |
var date = {}; | |
for (var i = 0, ii = events.length; i < ii; i++) { | |
if (!date[events[i]['date']]) { | |
date[events[i]['date']] = []; | |
}; | |
date[events[i]['date']].push(events[i]); | |
} | |
console.log(date); |
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
var data = { | |
events: [ | |
{ | |
id: 1, | |
date: '1/1/2011' | |
}, | |
{ | |
id: 2, | |
date: '1/1/2011' | |
}, | |
{ | |
id: 3, | |
date: '2/1/2011' | |
}, | |
{ | |
id: 4, | |
date: '2/1/2011' | |
}, | |
{ | |
id: 5, | |
date: '2/1/2011' | |
}, | |
{ | |
id: 6, | |
date: '3/1/2011' | |
}, | |
{ | |
id: 7, | |
date: '3/1/2011' | |
}, | |
{ | |
id: 8, | |
date: '4/1/2011' | |
} | |
] | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment