Skip to Content

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.

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    avatar image
    Former Member
    Apr 26, 2016 at 06:11 AM

    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!

    Add comment
    10|10000 characters needed characters exceeded