Learn JavaScript
❯ strings_regex.split_join

split & join in JavaScript

$concept

split and join are inverses across the string/array boundary: "a,b,c".split(",") makes ["a","b","c"], and ["a","b","c"].join(",") remakes the string. Split accepts strings or regex (with limit caps), join accepts any separator — together they tokenize, transform (via array methods between), and reassemble.

Edge behaviors to know: splitting "" gives [""], consecutive delimiters yield empty strings ("a,,b".split(",") has three parts), and join coerces elements (null/undefined become empty). CSV with quoted commas needs a real parser — split can't see quoting.

$how it works
1

split tokenizes

"a,b,c".split(",") → three parts; string or regex separator plus optional limit.

2

join reassembles

["a","b"].join("-") → "a-b" — any separator, elements coerced, no trailing separator.

3

Transform between

s.split(" ").map(...).join(" ") — tokenize, process as arrays, rejoin: the text pipeline shape.

4

Know the edges

Empty strings, consecutive delimiters, quoted commas — each breaks naive splitting differently.

$example
let csv = "ada,36,dev";
let parts = csv.split(",");
console.log(parts.length, parts[0]);
console.log(parts.join(" | "));
Output
3 ada
ada | 36 | dev
1Split on commas yields three fields; parts[0] is ada.
2Join with " | " reassembles into display form.
3Split apart, join together — the round trip that structures text work.
$use cases
CSV-ish parsing (simple, unquoted) with split
Word counting and text pipelines via split-map-join
Display joining with custom separators
Real CSV parsers where quoting and escapes appear

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Re-implement each visualized algorithm in JavaScript yourself — building beats watching.