how to use the contains function from the underscore library in typescript

To use the contains function from the Underscore library in TypeScript, you can install the Underscore library using npm and then import it in your code.

Here is an example:

index.ts
import * as _ from 'underscore';

const array: number[] = [1, 2, 3, 4, 5];

// Check if array contains number 3
if (_.contains(array, 3)) {
  console.log('Array contains 3');
} else {
  console.log('Array does not contain 3');
}
229 chars
11 lines

In this example, the contains function from the Underscore library is used to check if the array contains the number 3. The function returns true if the value is present in the array and false otherwise.

gistlibby LogSnag