What are the benefits of using a framework for something as simple as this? Here is a JavaScript solution that effectively groups elements by a specified property, making it convenient to manipulate the resulting object.
var elements=[
{name: 'foo', type: 'product'},
{name: 'bar', type: 'product'},
{name: 'john', type: 'product'},
{name: 'no name', type: 'product'},
{name: 'foo', type: 'product'},
{name: 'bar', type: 'product'},
{name: 'john', type: 'product'},
{name: 'no name', type: 'product'},
{name: 'no name', type: 'product'},
{name: 'no name', type: 'product'},
{name: 'no name', type: 'product'},
];
function groupByProperty(propName, elements) {
var groupedItems = {};
for (var i = 0, length = elements.length; i < length; i++) {
var item = elements[i];
var value = item[propName].trim();
var group = groupedItems[value];
if (group === undefined) {
group = [item];
groupedItems[value] = group;
} else {
group.push(item);
}
}
return groupedItems;
}
var results = groupByProperty('name',elements);