Underscore.JS - isEmpty 方法
语法
_.isEmpty(object)
isEmpty 方法检查对象是否为空、字符串是否为长度或数组是否为空。请参阅以下示例 −
示例
var _ = require('underscore'); //示例 1:检查对象是否为空 var result = _.isEmpty({}); console.log(result); //示例 2:检查字符串是否为空 result = _.isEmpty(""); console.log(result); //示例 3:检查数组是否为空 result = _.isEmpty([]); console.log(result);
将上述程序保存在tester.js中。运行以下命令执行该程序。
命令
\>node tester.js
输出
true true true
underscorejs_comparing_objects.html