split()

ES3+

Divides a string into an ordered list of substrings and returns them as an array.

Syntax

string.split(separator, limit)

Parameters

separator string | RegExp

The pattern describing where each split should occur

limit number optional

Limit on the number of substrings to return

Return Value

Array

An Array of strings split at each point where the separator occurs

Examples

JavaScript
const str = 'Hello World';
console.log(str.split(' '));
console.log(str.split(''));
Output:
// ['Hello', 'World'] ['H', 'e', 'l', 'l', 'o', ' ', 'W', 'o', 'r', 'l', 'd']

Related Methods