Use the subscribe API to add channels to the current list of subscribed channels. To unsubscribe from one or more of the currently subscribed channels, use the unsubscribe
API and pass the channel(s) that need to be removed.
// subscribe to an initial array of channels pubnub.subscribe({ channels: ['channel2', 'channel3'] }); // some time later in your code, you can add more channels to the existing list pubnub.subscribe({ channels: ['channel4', 'channel5', 'channel10'] }); // at some point you may need to unsubscribe from some channels pubnub.unsubscribe({ channels: ['channel3', 'channel2'] }); // finally, you can unsubscribe from all remaining channels pubnub.unsubscribeAll();