This is because Array.prototype.filter
returns an array. MDN reference for Array.prototype.filter
.
For example, these two statements are equivalent:
[1, 2, 3].filter(function(){
return false
}).length
and
[].length
This is because this:
[1, 2, 3].filter(function(){
return false
})
returns []
.
var one = [1, 2, 3].filter(function() {
return false
}) // Removes all elements from array
var two = []
console.log(one, one.length)
console.log(two, two.length)
CLICK HERE to find out more related problems solutions.