String.split

split — Splits a string.

Description

String.split([string separator, [integer limit]])

Parameters

Name Description Type Default Optional
separator string Yes
limit integer Yes

Return values

array.

Examples

Example #1 – split example
console.log('Hello World'.split()); // ["Hello World"] console.log('Hello World'.split(' ')); // ["Hello", "World"] console.log('Foo, Bar, Baz, Qux'.split(', ')); // ["Foo", "Bar", "Baz", "Qux"] console.log('Foo, Bar, Baz, Qux'.split(',')); // ["Foo", " Bar", " Baz", " Qux"] console.log('Foo, Bar, Baz, Qux'.split(', ', 2)); // ["Foo", "Bar"]

External references