I created a filter method called itemsWithFilter to filter the items object and store the results in itemsResult.
This function initially works as expected, but I noticed that it automatically updates the original items object. However, I intended for the results to only be written to itemsResult.
Can anyone explain why this is happening and suggest ways to prevent it? I want the itemsWithFilter method to exclusively return its results to itemsResult.
Here is the Fiddle link: https://jsfiddle.net/afdz3yLt/1/
Below is my implementation of the itemsWithFilter function
itemsWithFilter: function(filter) {
var items = this.items.data;
var result = {}
console.log("Run itemsWithFilter")
Object.keys(items).forEach(key => {
const item = items[key]
console.log(`filter: ${filter}: checking item ${item.id} with category id: ${item.category.id}`)
if (item.category.id == filter) {
result[key] = item;
}
})
this.itemsResult.data = result;
}