How to use _.where method from underscore.js library for more elaborated searchs

Viewed 20890
var a = {
    "title": "Test 1",
    "likes": {
        "id": 1
    }
}

var b = {
    "title": "Test 2",
    "likes": {
        "id": 2
    }
}


var c = [a, b];

var d = _.where(c, {
    "title": "Test 2",
    "likes": {
        "id": 2
    }
});
//d => outputs an empty array []

In this situation i would expect to get the reference to object in memory but d but actually it just works on root properties.

_.where(c, {title: "Test 2"});
=> outputs [object]

where object is the reference for c[1];

EDIT: found a possible solution using _.filter()

_.filter( c, function(item){ 
    if (item.title == "Test 1" && item.likes.id == 1){
        return item;
    } 
})

outputs => [object] with reference for variable a
1 Answers
Related