Skip to content

Function: includesValue()

ts
function includesValue<T>(
   collection, 
   value, 
   position?): boolean;

Checks whether an array or string includes a value. 检查数组或字符串中是否包含指定值。

Type Parameters

Type ParameterDescription
TThe array item type / 数组元素类型

Parameters

ParameterTypeDefault valueDescription
collectionstring | readonly T[]undefinedThe array or string to search / 要搜索的数组或字符串
valuestring | TundefinedThe value to search for / 要搜索的值
positionnumber0The start position / 起始搜索位置

Returns

boolean

true when the value is found / 找到目标值时返回 true

Example

ts
includesValue([1, 2, 3], 2)
// => true

Since

1.2.0

Released under the MIT License.