var x = {
"name": "Example 1",
"status": {
"id": 1
}
}
var y = {
"name": "Example 2",
"status": {
"id": 2
}
}
var z = [x, y];
var w = _.where(z, {
"name": "Example 2",
"status": {
"id": 2
}
});
//w => returns an empty array []
In this scenario, the expectation was to obtain a reference to the object in memory with w, however, it actually operates only on root properties.
_.where(z, {name: "Example 2"});
=> returns [object]
where object represents the reference for z[1];
EDIT: discovered a possible solution using _.filter()
_.filter( z, function(entry){
if (entry.name == "Example 1" && entry.status.id == 1){
return entry;
}
})
returns => [object] with reference for variable x