I need where but with not case. For example, I would like to find plays, which have no name "Shakespeare":
_.where(listOfPlays, {author: !"Shakespeare", year: 1611});
^^^^^^^^^^^^^
NOT Shakespeare
How can I do it with underscore
?
Yes you can do it using both side ToUpper() or ToLower() function in your filter condition. in that case user type lower or upper case but search method will for both side.
To do a case-insensitive comparison, use the ILIKE keyword; e.g., column ILIKE 'aBc' and column ILIKE 'ABC' both return TRUE for 'abc' . In contrast, MySQL and MS SQL Server have case-insensitive behaviors by default. This means WHERE column = 'abc' returns TRUE for e.g., 'abc' , 'ABC' , or 'aBc' .
Python strings equality can be checked using == operator or __eq__() function. Python strings are case sensitive, so these equality check methods are also case sensitive.
The most basic way to do case insensitive string comparison in JavaScript is using either the toLowerCase() or toUpperCase() method to make sure both strings are either all lowercase or all uppercase.
_.filter(listOfPlays, function(play) {
return play.author !== 'Shakespeare' && play.year === 1611;
});
http://underscorejs.org/#filter
where
is nothing more than a convenient wrapper around filter
:
// Convenience version of a common use case of `filter`: selecting only objects
// containing specific `key:value` pairs.
_.where = function(obj, attrs) {
return _.filter(obj, _.matches(attrs));
};
https://github.com/jashkenas/underscore/blob/a6c404170d37aae4f499efb185d610e098d92e47/underscore.js#L249
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With