These are my two arrays:
let allItems = ["apple", "banana", "cherry", "date"];
let selectedItems = ["apple", "date"];
The existing code is as follows:
let allItems = ["apple", "banana", "cherry", "date"];
let selectedItems = ["apple", "date"];
isItemSelected = (item, $event) => {
for (let i = 0; i < allItems.length; i++) {
if (selectedItems.indexOf(item) > -1) {
return true;
}
else {
return false;
}
}
}
How can we improve this code using foreach (linq) in TypeScript?
Appreciate your suggestions!