Firstly, forEach
does not return anything. So you should use .filter
instead.
for each product check if the tags array of objects has at least one tag
of shows.
Secondly, the condition should be ===
instead of !==
, Besides, need return the true if all products are passing the some() not filter
==> Solution:
const allValidProducts = this.products.filter(product => product.tags.some(item => item.tagName === 'shows'));
const result = allValidProducts.length === this.products.length;
So as you can see, the .some
works fine.
const array = [1, 2, 3, 4, 5];
console.log(array.some(element => element % 2 === 0));
// expected output: true
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…