Underscore.JS isMatch方法
语法
_.isMatch(object, properties)
isMatch方法检查对象是否包含属性。请参阅以下示例 −
示例
var _ = require('underscore');
var student = {name: 'Sam', age: 10 }
//Example 1: Check if name Sam is present in student
var result = _.isMatch(student, {name: 'Sam'});
console.log(result);
//Example 2: Check if age 10 is present in student
result = _.isMatch(student, {age: 10});
console.log(result);
将上述程序保存在 tester.js 中。运行以下命令来执行该程序。
命令
>node tester.js
输出
true
true