Skip to content

Instantly share code, notes, and snippets.

@fatihacet fatihacet/code.js
Created Oct 24, 2011

Embed
What would you like to do?
Groups given object by a key
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);
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
You can’t perform that action at this time.