Underscore.JS - has 方法
语法
_.has(object, key)
has 方法检查对象中是否存在键。请参阅以下示例 −
示例
var _ = require('underscore');
var student = {name: 'Sam', age: 10 }
// 示例 1:检查现有键
console.log(_.has(student, 'name'));
// 示例 2:检查不存在的键
console.log(_.has(student, 'marks'));
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
true false
underscorejs_updating_objects.html