On this page
String.split
Prev: slice | Up: String | Next: includes
Rel: String, String, RegExp & Intl Guide
Ref: MDN Web Docs — String.split
Tags: #public #web #javascript #builtins #string #tier/core
Signature & Overview
str.split(separator, limit?)
Splits str into an array of substrings using a string or RegExp delimiter.
Notes & Pitfalls
- Beware
"a,b,c".split(",", 2): Thelimitparameter truncates the result (["a", "b"]), unlike Python'smaxsplitwhich keeps the remainder in the last slot.
Example
console.assert(JSON.stringify("a,b,c".split(",")) === '["a","b","c"]');
console.assert(JSON.stringify("a,b,c".split(",", 2)) === '["a","b"]');
Linked from
Related notes
- tuts/javascript/builtins/String/includes Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/slice Linked here; links to this page; shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String Linked here; links to this page; shared tags: #builtins, #javascript, #string, #web
- tuts/javascript/builtins/string_regexp_and_intl Linked here; shared tags: #builtins, #javascript, #web
- tuts/javascript/builtins/String/matchAll shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/replaceAll shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/substr shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/String/trim shared tags: #builtins, #javascript, #string, #tier, #web
- tuts/javascript/builtins/Array/at shared tags: #builtins, #javascript, #tier, #web
- tuts/javascript/builtins/Array/filter shared tags: #builtins, #javascript, #tier, #web