includes
collectionChecks if value is in collection. If collection is a string, it's checked for a substring of value.
Signature
includes<T>(collection: T[] | string, value: T | string, fromIndex?: number): booleanParameters
| Name | Type | Description |
|---|---|---|
collection | T[] | string | The collection to inspect |
value | T | string | The value to search for |
fromIndex? | number | The index to search fromDefault: 0 |
Returns
boolean - Returns true if value is found, else false
Examples
Check array
import { includes } from 'dashlite'
console.log(includes([1, 2, 3], 1))
console.log(includes([1, 2, 3], 4))Output:
true
falseCheck string
import { includes } from 'dashlite'
console.log(includes('dashlite', 'dash'))
console.log(includes('dashlite', 'foo'))Output:
true
falseAvailable since version 1.2.0