I am using Underscore.js in my project and came across a weird behavior. When I filter the array with changes_summary === 2 I am getting the desired result but when I use the same with changes_summay === 0, I am not getting any output.
Following is the code:
var result={
"data": [
{
"id": 956,
"changes_summary": 2,
"name": "Pradeep",
"age": 32
},
{
"id": 956,
"changes_summary": 0,
"name": "praveen",
"age": 22
}
]
}
var filtered = _.filter(result.data, function(obj){
return (obj.changes_summary && obj.changes_summary === 2)
});
//working when comparing with changes_summary with 2 but not working when comparing with 0
console.log(filtered);
Please let me know where I am going wrong. Link to Jsfiddle attached: Jsfiddle
obj.changes_summary &&remove this to check for0.0isfalsySee jsfiddle.net/tusharj/2j13o0be/1