2.24 size
2.24.1 语法:
_.size(list)
2.24.2 说明:
返回列表的长度。
示例一:返回数组、对象、字符串的长度
//取数组的长度
var length
length = _.size([1, 2, 3]);
console.log(length); //=> Number 3
//取对象的长度
length = _.size({a:1, b:2});
console.log(length); //=> Number 2
//取字符串的长度
length = _.size('你好吗?');
console.log(length); //=> Number 4
示例二:返回伪数组的长度
var length = _.size({length: 3, 0: 0, 1: 0, 2: 0});
console.log(length); //=> Number 3
示例三:返回arguments的长度
(function(){
console.log(_.size(arguments)); //=> Number 4
}(1, 2, 3, 4));
2.24.3 非集合的情况返回0
console.log(_.size(null)); //=> Number 0
console.log(_.size(true)); //=> Number 0
console.log(_.size(false)); //=> Number 0
console.log(_.size(undefined)); //=> Number 0
console.log(_.size(0)); //=> Number 0
console.log(_.size(123)); //=> Number 0