Suppose a given string exists, s="abc"
Is there any way to check if that given string exists in an array, such as,
arr=["pnq","dwksnn","inabcpi","poals"]
Any method/way to see so that a condition will return true in such a case?
Suppose a given string exists, s="abc"
Is there any way to check if that given string exists in an array, such as,
arr=["pnq","dwksnn","inabcpi","poals"]
Any method/way to see so that a condition will return true in such a case?
5
Answers
you need to search over each array element and check if the given string is contained within any of the elements, you can use the
some()
method. Here’s the JavaScript code:Something like this? using the
.includes()
?Simple, you need to iterate over the given array and check if this string exists in each of the strings within the array.
You can use the array method
some
, and the string methodincludes
.we can use the includes() method to check.