Technology Programming

How to Split a String in JavaScript

    • 1). Launch the standard, plain-text editor application that is available on your computer.

    • 2). Enter the following code to test the JavaScript:



      <script type="text/javascript">

      var fullstring="The rain in Spain";

      var URL="";

      document.write("This is the slice() function: " + fullstring.slice(3,8)+"");

      document.write("This is the substr() function: " + fullstring.substr(4,4)+"");

      document.write("This is the substring() function: " + fullstring.substring(3,8)+"");

      document.write("This is the split() function: " + fullstring.split(" ")+"");

      document.write("Spliting the URL with the split() function: " + URL.split("/")+"");


    • 3). Click the "File" menu. Select the "Save" option. Save under the file name "test.html".

    • 4). Launch the Web browser that is available on your computer. Click the "File" menu, and select "Open File."

    • 5). Locate the file "test.html" you just created, select it, and click Open."

Leave a reply