Skip to main content Link Search Menu Expand Document (external link)

split() : Split String into Array


On this page

Summary

Split a string into an array of substrings based on a separator.

Signature

split(str, separator)

Parameters

Parameter Type Required Description
str String Yes The string to split
separator String Yes The separator to split on

Returns

Type: Array of strings

An array containing the split substrings.


Examples

Split CSV

<ul>

  <li></li>

</ul>

Data:

doc.Params["model"] = new {
    tags = "javascript, html, css, react"
};

Output:

<ul>
  <li>javascript</li>
  <li>html</li>
  <li>css</li>
  <li>react</li>
</ul>

Split Full Name

<p>First Name: </p>
<p>Last Name: </p>

Data:

doc.Params["model"] = new {
    fullName = "John Doe"
};

Output:

<p>First Name: John</p>
<p>Last Name: Doe</p>

Split Path

<ul class="breadcrumb">

  <li></li>

</ul>

Data:

doc.Params["model"] = new {
    path = "home/documents/reports/2024"
};

Output:

<ul class="breadcrumb">
  <li>home</li>
  <li>documents</li>
  <li>reports</li>
  <li>2024</li>
</ul>

Count Occurrences

<p>Words: </p>

Data:

doc.Params["model"] = new {
    sentence = "This is a sample sentence"
};

Output:

<p>Words: 5</p>

Notes

  • Returns array of substrings
  • Empty strings included if separator appears consecutively
  • If separator not found, returns array with single element (original string)
  • Case-sensitive matching
  • Use with `` to iterate results
  • Use with trim() to clean up whitespace
  • Opposite of join() function

See Also