0👍
✅
filter
method if it doesn’t find any matched item it returns an empty array []
, so you could keep one filter method that returns an array (filled or empty) and iterate over it :
AreAllItemsAvailable() {
return this.allItems.filter(
item => this.availableItems.includes(item.id) && item.count === '1',
)
}
in template :
v-for="item in AreAllItemsAvailable"
0👍
To clean, you could add an intermediary computed value :
finalAvailableItems() {
return this.allItems.filter(
item => this.availableItems.includes(item.id)
)
}
AreAllItemsAvailable() {
return this.finalAvailableItems.every(item => item.count === '1');
},
No need to return a null value : if your objective is to check if all items are available, the boolean AreAllItemsAvailable
will return False if finalAvailableItems
is empty
v-if= "!AreAllItemsAvailable"
Source:stackexchange.com