Why 0 is not returned by the following filter ?
[0, 5, 4].sort().filter(function(i){return i}) // returns : [4, 5]
.filter() function by default excludes falsy items from filtered output.
// ----- falsy items in JS --------
false
null
undefined
0
NaN
'' //Empty string
Solution :
If you still want to keep them, just remember this short tip :
true to keep the element, false otherwise.Example :
[0, 5, 4].sort().filter(function(i){
return true // returning true to keep i element
});