Just exists a underscoreJs method to convert a Object having some properties to an Collection of objects having a key property?
I mean if exists a simple method in underscorejs that is equivalent of this:
function objectToCollection(obj, propertyKey) {
return _.map(obj, function(o, key) {
b[propertyKey] = key;
return o;
});
}
var obj = {
prop1: {val:2},
prop2: {val:3},
prop3: {val:5},
prop4: {val:7}
};
objectToCollection(obj, 'name');
Result:
[
{name: 'prop1', val: 2},
{name: 'prop2', val: 3},
{name: 'prop3', val: 5},
{name: 'prop4', val: 7}
]