For instance, the following string has three elements separated by commas:
“First element, Second element, Third element”
var thisVar = "First element,Second element,Third element"; var anotherVar = thisVar.split(",");
anotherVar is now an array containing three elements.
1. Open a new HTML document in your preferred HTML or text editor.
2. Create the body of the document with opening and closing body tags:
3. Insert a script block in the body of the document:
4. Create a variable named myVariable and assign a comma separated text string to it:
var myVariable = "a,b,c,d";
var stringArray = myVariable.split(",");
6. Use the document.write method to output the elements of the array so that the final script looks like
7. Save the file and close it.
8. Open the file in a browser, and you should see the text “abcd”,