The split() function outputs an array of items. Instead of selecting the first item through "[0]", assign the whole array to a variable and loop over that, in the format:
for (var count = 0; count < maxCount; count++) {
// Action to be repeated here
}
A problem you'll have is your source string is in the format "Id(Type),Id(Type)". Splitting on just "(Type)" will leave the commas in the item, so your stripped items would look like "320151" and ",320145". Ensure you include the comma (and make sure your source string has a comma at the end too or your last item won't match the split conditions and will still say "Id(Type)".
So your code would look like:
var data = {
"selectedProducts": {
"selectedSubscriptionIds": "320151(Products),320145(Products),"
}
};
var SelectedSubscriptionIds = data.selectedProducts.selectedSubscriptionIds;
console.log(SelectedSubscriptionIds); //320151(Products),320145(Products),
var subscriptionIdArray = SelectedSubscriptionIds.split("(Products),");
for (var i = 0, i < subscriptionIdArray.length; i++) {
var subscriptionId = subscriptionIdArray[i];
console.log(subscriptionId); // 320151, then 320145 etc
}
I'm not sure why you need to specify a subscriptionId as "Id(Type)" when it's already inside the "selectedProducts" category. If it's purely for the sake of splitting then you could leave it out and just split on ","
var data = {
"selectedProducts": {
"selectedSubscriptionIds": "320151,320145"
}
};
var SelectedSubscriptionIds = data.selectedProducts.selectedSubscriptionIds;
console.log(SelectedSubscriptionIds); //320151,320145
var subscriptionIdArray = SelectedSubscriptionIds.split(",");
for (var i = 0, i < subscriptionIdArray.length; i++) {
var subscriptionId = subscriptionIdArray[i];
console.log(subscriptionId); // 320151, then 320145 etc
}
0index at the end of the statement which returns the first element of the array, remove that and t will work fine.