Reputation: 1751
My filter function in javascript isn't working:
var a=["apple", ""];
a.filter(function(x){x.length<0});
a// expect to return ["apple"], but get []
Upvotes: 1
Views: 44
Reputation: 149000
Your filter function needs to return a value. I'm also guessing you want .length > 0
since there is no such thing as a string with a negative length. Finally, the filter
method will return a new array, so you'll probably want to capture the result in a
.
In the end, it would look something like this:
a = a.filter(function(x){return x.length > 0});
Upvotes: 3