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.tsx159 chars7 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.tsx161 chars7 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