How to extract elements from a delimited list using JavaScript

  • KM02971443
  • 29-Sep-2017
  • 29-Sep-2017

This document has not been formally reviewed for accuracy and is provided "as is" for your convenience.

Summary

How to extract elements from a delimited list using JavaScript

Question

The following javascript code helps to separate each of the elementes from a list separated by semicolon.
For example, the eventout records may contain a list of the emails to which a notification will be sent

Answer

var

 

thelist="firstemail@domain.com;secondemail@domain.com;thirdemail@domain.com;fourthemail@domain.com;";
var count=1;
var
posdelimiter=0;
var oneemail=""
;
while
(thelist.length!=0)
{
        posdelimiter=thelist.indexOf(
";");
//This delimiter can be changed to any character that separate the list, in this case a semicolon
        oneemail=thelist.substring(0,posdelimiter);
        // Section to add any code where each of the values from the list will be used. In this case, olny print each value
        print("element number "+count+" from the list is: "
+oneemail);
        //
        thelist=thelist.substring(posdelimiter+1,thelist.length);
        count++;
}