Skip to Content

Archived discussions are read-only. Learn more about SAP Q&A

How to convert in to Java script array

Hi Experts, How can i convert  for example (1;2;3)  to Java script array [ "1"  , "2"  , "3"  ]; Another example (1,9,12,36,25)  to  ["1" , "9" ,"12" ,"36" , "25" ] I will have opening and closing brackets (  , )  with  1;2;3 .  so it  will be (1;2;3)  . Is there a Function module in Java script ? Best regards, pradeep.

Former Member replied


for these cases you can use a combination of the standard functions split() and substr(). For the latter, take the help of the length parameter to remove the trailing bracket.

This should do the trick (untested!)

var myText = "(1;2;3)";

var myTextContent = myText.substr(1,myText.length - 2);

var myArray = myTextContent.split(";");

Good luck!

0 View this answer in context
Not what you were looking for? View more on this topic or Ask a question