Function Updated 17 Oct 2026
String.split([separator], [limit])
Splits a single string into an array of strings based on the specified separator.
In template mode there is also an older global helper split(text) — a function, not a method — which splits by line breaks and drops empty lines.
Parameters
separatorstring | RegExpoptionalText or regular expression to split the string by. Empty text splits into single characters. Without a separator, the whole string is returned as the only item.
limitnumberoptionalMaximum number of items to return. 0 returns an empty array.
Returns
An array of strings.
Example
Mixed HTML (or any text file) with inline JavaScript between hash signs.
#{
var text = "1,2,3,4,5,6,7";
/* Split text by comma */
var array = text.split(",");
for(let item of array)
{
}#
<div>#item#</div>
#}#The template above produces this output:
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>