Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Splitting a String in javascript

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 128
    Comment on it

    To split a string in javascript, we use split() method which splits the string into an array of substrings.

    Syntax: string.split(separator);

    Where separator specifies the character(s) to use for separating the string, and if this separator ( or delimeter) is found in the main string , separator is removed from that string and an array is return consisting of substrings. If separator is not found, the array contains one element consisting of the entire string.

    Eg: Below is the function for using split() method:

    function splitString() {
        var strToSplit = "My Split Program.";
        var separator=" ";
        var strResult = strToSplit.split(separator);
        for(var i=0;i<strResult.length;i++)
        {
            alert(strResult[i] );
        }
    }
    

    Output of above function:
    strResult[0]= My
    strResult[1]=Split
    strResult[2]=Program.

 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: