Skip to content

includes ​

The includes function checks if an array or string contains a given value.

Syntax ​

typescript
includes<T>(array: T[] | string, value: T | string, fromIndex?: number): boolean;

Parameters ​

NameTypeDescription
arrayT[] | stringSource array or string
valueT | stringValue to search for
fromIndexnumberStarting index for search (optional)

Returns ​

TypeDescription
booleanReturns true if the value is found

Examples ​

typescript
includes([1, 2, 3], 2); // => true
includes("abc", "b"); // => true
includes([1, 2, 3], 4); // => false

Notes ​

  • Equivalent to the native Array.prototype.includes method.
  • Useful for quick searches in arrays or strings.

References ​

Released under the MIT License.