Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Creating a String from an Array

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 177
    Comment on it

    Hello reader's in this tutorial we are going to create a string from array. We will use array object method to join an array element into a string. The in-built join method will join the array elements into a string.

     

    Syntax:-

    var fruitArray = ['apple','peach','lemon','lime'];
    var resultString = fruitArray.join('-'); // apple-peach-lemon-lime

     

    The one optional parameter is taken by the array join method. To make a separate string use a delimiter, when the array joined in this case by using dash(-). All of the array elements concatenated when it returns a string.

     

    The values converted into a equivalent string if the array contains anything other than strings.

     

    Syntax:-

    var numberArray = [1,2,3,4,5]; // array literal containing number elements
    var resultString = numberArray.join('+'); // returns string with 1+2+3+4+5

     

    By default the comma is inserted between array element if we don't give a delimiter parameter.

     

    Syntax:-

    var numberArray = [1,2,3,4,5];
    var resultString = numberArray.join(); // returns string with 1,2,3,4,5

     

    Hope, this tutorial will help you to create a string from array.

 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: