Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to convert Array into a String in JavaScript

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 113
    Comment on it

    Conversion of array into a string in JavaScript.

    There are two method to convert element of array into a string in JavaScript.

    1st Method: toString()-> toString() method joins the array & returns one string that contain each element of array.

    2nd Method: Join()-> join() method joins all elements of an array into a string.

    Example of toString()

    var Fruit = ['Apple', 'Orange', 'Banana', 'Grape'];
    var FruitString = Fruit.toString(); // assigns 'Apple,Orange,Banana,Grape' to FruitString
    

    Example of join()

    With the help of join method, we can join array in 4 different ways by using comma, space, plus and an empty string..

    var Fruit = ['Apple', 'Orange', 'Banana', 'Grape'];
    var FruitString = Fruit.join(); // assigns 'Apple,Orange,Banana,Grape' to FruitString
    var FruitString = Fruit.join(', '); // assigns 'Apple, Orange, Banana, Grape' to FruitString
    var FruitString = Fruit.join(' + '); // assigns 'Apple + Orange + Banana + Grape' to FruitString
    var FruitString = Fruit.join(''); // assigns 'AppleOrangeBananaGrape' to FruitString
    

 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: