Underscore 源码解读 - Collection Functions

Underscore - Collection Functions

contains

别名:includes, include
语法:_.contains( list, value [ , fromIndex ] )
1
2
3
4
5
6
7
// Determine if the array or object contains a given item (using `===`).
// Aliased as `includes` and `include`.
_.contains = _.includes = _.include = function(obj, item, fromIndex, guard) {
if (!isArrayLike(obj)) obj = _.values(obj);
if (typeof fromIndex != 'number' || guard) fromIndex = 0;
return _.indexOf(obj, item, fromIndex) >= 0;
};