Skip to content

includes

js
_.includes(collection, value, [fromIndex=0])

检查 value 是否在 collection 中。如果 collection 是字符串,则检查它是否为 value 的子字符串,否则使用 SameValueZero 进行相等性比较。如果 fromIndex 为负,则将其用作距 collection 末尾的偏移量。

¥Checks if value is in collection. If collection is a string, it's checked for a substring of value, otherwise SameValueZero is used for equality comparisons. If fromIndex is negative, it's used as the offset from the end of collection.

新增于

¥Since

0.1.0

参数

¥Arguments

  1. collection (数组|对象|字符串):要检查的集合。

    ¥collection (Array|Object|string): The collection to inspect.

  2. value (*):要搜索的值。

    ¥value ()*: The value to search for.

  3. [fromIndex=0] (数值):要从中搜索的索引。

    ¥[fromIndex=0] (number): The index to search from.

返回

¥Returns

(布尔):如果找到 value,则返回 true,否则返回 false

¥(boolean): Returns true if value is found, else false.

示例

¥Example

js
_.includes([1, 2, 3], 1);
// => true

_.includes([1, 2, 3], 1, 2);
// => false

_.includes({ 'a': 1, 'b': 2 }, 1);
// => true

_.includes('abcd', 'bc');
// => true

Lodash v4.17 中文网 - 粤ICP备13048890号