Logic to subscribe to categories and question about iteration

Hey,

I am using a sectionSelect to select particular categories to subscribe to. Another view would only list items of the selected categories.

So far, I simply determine a subscription based on a “subscribed = 1” element for a particular category

0: {id: 0, cat: "A", subscribed: 0}
1: {id: 1, cat: "B", subscribed: 1}
2: {id: 4, cat: "C", subscribed: 0}

So now my ionChange function returns a list of objects the user wants to update his subscription to. Like the list above. So now I would first have to remove all other active subscriptions by setting subscribed to 0 for all categories, and in another go update all subscriptions to 1 for the selection. I do this in the following manner:

  updateClick($event){
    this.myItemProvider.clearSubscriptions();
    let i = 0;
    $event.forEach((cat) => {
      this.myItemProvider.setSubscription($event[i].id);
      i++;
    }); 
    }

I wondered if there is a more beautiful approach for that, and if I would run into any issues with that.

Furthermore, is there a more modern approach to iterate through the objects other than foreach with an manually incrementing i++?

Thanks in advance!

Does clearSubscriptions() actually unsubscribe from Observables, or are you just clearing the contents of an array?

Hm no it’s simply changing the values to 0, that’s it, and in the view I’d then simply not show the items of my provider if the subscription of the category is 0. In the tutorials I went through I’ve never seen the use of Observables, so I will look into that.

So you just need to make a shallow copy of the event array?