I have an array called items
which contains a list of strings which I want to search against me key_res
array which contains some keywords I need either a true or false value on.
This is the code I have so far which works:
const items = ['Quality 1080p', 'Quality 720p', 'Quality 4K'];
const key_res = ['4K', '6K'];
contains_string = items.every(item => {
if(key_res.some(string => item.includes(string))) {
return false;
}
return true;
});
Is there a way I can return a boolean value easier than going through a loop and then setting a boolean?
2
Answers
I’m not sure if this helps, it really doesn’t save a lot of code, but using
map
instead offorEach
will loop and allow you to return a value. So now you onlyconsole.log
one timeUse
some
instead offorEach
: