Animations
API
Arrays
Async
Basics
Challenges
Classes
Console
Dates
Debugging
DOM Elements
DOM Methods
DOM Properties
Event Listeners
Flow Control
Forms
Functions
Global Functions
JSON
Keywords
Libraries (3rd party)
Math
Modules
Objects
Snippets
String
Types
Widgets
Window Object
A string can be converted to an array with the split()
method. If the separator is omitted, the returned array will
contain the whole string in index[0].
// create string
var txt = "a,b,c,d,e";
// split into an array
array = txt.split(",");
// loop through array and make an html string
let x = 0;
let numberOfLoops = array.length;
let htmlOutput = "";
do
{
htmlOutput += array[x] + "<br />";
x++;
}
while (x < numberOfLoops);
document.getElementById("demo1").innerHTML=htmlOutput;