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
underscorejs_comparing_objects.htm
广告