cancel
Showing results for 
Search instead for 
Did you mean: 

How to convert in to Java script array

pakula123
Participant
0 Kudos

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.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hi,

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!

pakula123
Participant
0 Kudos

Hi Merten , In my case it does not contain " in front  and last of the numbers before brackets so it is not a string. Also this is a variable so I can have many numbers in between or less numbers. The issue for me is it is not a string with ". Best regards, Pradeep.

pakula123
Participant
0 Kudos

Hi Merten, There are no brackets in my case and have used similar logic that was mentioned and it worked. Awarded points for you . Best regards, pradeep.

Answers (0)