I have a string apple_mango_banana
and an array containing [apple,mango]
.
I want to check if my string contains all of the elements present in the array, if so, I want to show a div with the same ID as my string.
Use every() function on the arr and includes() on the str; Every will return true if the passed function is true for all it's items.
var str = 'apple_mango_banana';
var arr = ['apple','banana'];
var isEvery = arr.every(item => str.includes(item));
console.log(isEvery);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With