Having this:
array = []
array.push(111,2122,333,9)
obj.user = {
'111' : {},
'2122' : {},
'333' : {},
'44' : {}
}
How can I get a new object containing only the elements that exist in the array?
In the case above, it would return:
{
'111': {},
'2122': {},
'111': {}
}
I have tried this:
var newObj = _.keys(_.pick(obj.user, function(value, key) {
if ( _.indexOf(array, parseInt(key)) != -1 ) {
return obj.user[key]
}
}));
Which works fine when testing on jsfiddle, but it crashes my app with process out of memory. The objects/arrays are not that large, maybe 20-30 items, but that piece of code gets executed quite a lot of times.