Skip to main content

split(stringToDivide, separatorCharacters)

Divides the passed string into an array of sub-strings


Device + Agent


Name Type Description
stringToDivide String Any string
separatorCharacters String Sub-string of one or more separator characters


Array — the collection of sub-strings


This function takes a string as its first parameter and searches that string for the character or characters contained in the string passed as its second parameter. If it finds any of these separator characters, it divides the main string at the location(s) of those characters and places the resulting sub-strings into a new array which it returns.

If none of the separator characters are found, the function returns an array containing the source string as a single item.

Because split() is implemented as a function, it does not use dot syntax.

JavaScript developers should take particular care with split() because it doesn’t create empty strings when multiple instances of the separator character(s) are encountered, as they might expect from JavaScript. Instead, it treats multiple instances of the separator as a single instance. For example, in Squirrel,

split("a//b/c", "/")

will yield the following array:

["a", "b", "c"]

However, the equivalent JavaScript code,


instead generates an extra array element: an empty string triggered by the second of the paired forward slashes, ie.

["a", "", "b", "c"]

Example Code