Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to convert Javascript Arrays to Comma seperated values

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 307
    Comment on it

    The toString() method can be used to convert an array into a string. It returs a result containing string and it will seperate the different elements in the array with commas.

    var group = ['one','two','three','four'];
    
    var conv = group.toString();

    The same thing can also be done by valueOf() method in javascript.

    var group = ['one','two','three','four'];
    
    var conv = group.valueOf();

    To convert comma seperated value to an array, split() method is used. It is used to seperate a string into array that contains substrings and also returns a new array.

    Syntax:

    var group = ['one','two','three','four'];
    
    var conv = group.valueOf();

    Seperator:  It can contain a regular expression or a character to split the string.
    Limit:  It defines the number of splits
     

    var group = ['one','two','three','four']
    
    var conv = "one,two,three,four"
    
    var groupArray = conv.split(",") //print groupArray[0] one.

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: