how to use the includes function from lodash in javascript

You can use the includes function from lodash to quickly determine whether an array includes a particular element.

Here is an example on how to use the _.includes function from lodash:

index.tsx
const _ = require("lodash");

const arr = [1, 2, 3, 4, 5];

console.log(_.includes(arr, 3)); // Output: true
console.log(_.includes(arr, 6)); // Output: false
159 chars
7 lines

In this example, we first require lodash and create an array called arr that has some values. We then use the _.includes function to check if the element 3 is in the array, which returns true. We then check if the element 6 is in the array, which returns false.

You can also use _.includes with strings:

index.tsx
const _ = require("lodash");

const str = "Hello World";

console.log(_.includes(str, "o")); // Output: true
console.log(_.includes(str, "z")); // Output: false
161 chars
7 lines

In this example, we create a string called str that has some characters. We then use the _.includes function to check if the character "o" is in the string, which returns true. We then check if the character "z" is in the string, which returns false.

gistlibby LogSnag