0

I have a list of objects which have a last name property and I would like to find the object with the last name which the user types in.

I can do this using the underscore filter function which works fine but the case matters. So for example if the last name is Jacobs in my object array and the user types jacobs, it will not find that object. How can I get make the filer find the object regardless of case?

This is how I currently use filter.

var user = _.filter(arr, function(item) {
    return item.lastname.indexOf(typedLastName) > -1;
});

Thanks!

0

1 Answer 1

1
var user = _.filter(arr, function(item) {
   return item.lastname.toLowerCase().indexOf(typedLastName.toLowerCase()) > -1;
});

Convert both of them to lowercase or uppercase , and then perform comparison

Sign up to request clarification or add additional context in comments.

1 Comment

Wow, for some reason I thought I couldn't use toLowerCase() before indexOf()...that totally works! Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.