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?
>Solution :
Use some instead of forEach:
let items = ['Quality 1080p', 'Quality 720p', 'Quality 4K'];
const key_res = ['4K', '6K'];
let bool = items.some(item => key_res.some(string => item.includes(string)));
console.log(bool);
items = ['Quality 1080p', 'Quality 720p'];
bool = items.some(item => key_res.some(string => item.includes(string)));
console.log(bool);