Say I have an array like this:
var arr = [
{type:\"orange\", title:\"First\"},
{type:\"orange\", title:\"Second\"},
{type:\"banana\", title:\"Thi
Just build a dictionary which holds the objects based on their title. You could do it like this:
js
var arr = [
{type:"orange", title:"First"},
{type:"orange", title:"Second"},
{type:"banana", title:"Third"},
{type:"banana", title:"Fourth"}
];
var sorted = {};
for( var i = 0, max = arr.length; i < max ; i++ ){
if( sorted[arr[i].type] == undefined ){
sorted[arr[i].type] = [];
}
sorted[arr[i].type].push(arr[i]);
}
console.log(sorted["orange"]);
console.log(sorted["banana"]);
jsfiddle demo: http://jsfiddle.net/YJnM6/