Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>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:</p> <pre><code>for (var count = 0; count &lt; maxCount; count++) { // Action to be repeated here } </code></pre> <p>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)".</p> <p>So your code would look like:</p> <pre><code>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 &lt; subscriptionIdArray.length; i++) { var subscriptionId = subscriptionIdArray[i]; console.log(subscriptionId); // 320151, then 320145 etc } </code></pre> <p>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 ","</p> <pre><code>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 &lt; subscriptionIdArray.length; i++) { var subscriptionId = subscriptionIdArray[i]; console.log(subscriptionId); // 320151, then 320145 etc } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload