Underscore.js is a JavaScript library that provides a lot of useful functions that helps in the programming in a big way like the map, filter, invoke etc. even without using any built-in objects.
The _.matcher() function is an inbuilt function in Underscore.js library of JavaScript which is used to find a predicate function which can inform you if a passed in object includes all the key-value properties that are given in the attrs parameter.
Syntax:
_.matcher(attrs)
Parameters: This function accepts a single parameter as mentioned above and described below:
- attrs: It is the attribute which has a key and a value pair.
Return value: This method returns a predicate function.
Example 1:
<!DOCTYPE html> <html> <head> <script type= "text/javascript" src=
</head> <body> <script type= "text/javascript" >
console.log(_.matcher({
picked: true , seeable: false }));
</script>
</body> </html> |
Output:
function(obj) { return isMatch(obj, attrs); }
Example 2:
<!DOCTYPE html> <html> <head> <script type= "text/javascript"
src=
</head> <body> <script type= "text/javascript" >
var attr = "GeeksforGeeks" ;
console.log(_.matcher(attr));
</script>
</body> </html> |
Output:
function(obj) { return isMatch(obj, attrs); }
Reference: https://underscorejs.org/#matcher