ThinkChat🤖让你学习和工作更高效,注册即送10W Token,即刻开启你的AI之旅 广告
## includes + [link](./includes "Link to this entry.") + [source](https://github.com/lodash/lodash/blob/4.5.0正式版/lodash.src.js#L7785 "View in source.") + [npm](https://www.npmjs.com/package/lodash.includes "See the npm package.") ``` _.includes(collection, value, [fromIndex=0]) ``` 检查 值 是否在 集合中,如果集合是字符串,那么检查 值 是否在字符串中。 其他情况用 [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero) 等值比较。 如果指定 `fromIndex` 是负数,从结尾开始检索。 ### 参数 1. collection (Array|Object|string) 要检索的集合 2. value (\*) 要检索的值 3. [fromIndex=0] (number) 要检索的 index 位置 ### 返回值 (boolean) 如果找到 value 返回 ture, 否则返回 false。 ### 示例 ``` _.includes([1, 2, 3], 1); // => true _.includes([1, 2, 3], 1, 2); // => false _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); // => true _.includes('pebbles', 'eb'); // => true ```