Typorithm · easy

split, join, slice

string-split-joincollectionssplitjoinslice
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn split, join, slice

0%

String Methods

split turns a string into an array of tokens on a separator; join glues an array back into a string. slice(start, end) extracts a substring and accepts negative indices counting from the end; substring does the same for positive indices only.

split(separator) tokenizes a string into an array: "a,b,c".split(",") yields ["a", "b", "c"]. join(glue) is its inverse, turning an array back into one string.

slice(start, end) returns the substring from start up to (but not including) end. Omit end to go to the string's end, and use negative indices to count from the back: slice(-2) takes the last two characters.

substring(start, end) is similar but treats negative arguments as 0, so reach for slice when you want end-relative indexing.

01

split breaks a string into an array of tokens.

02

join glues an array into a string.

03

slice accepts negative indices; substring does not.

const parts = "a,b,c".split(",")
const csv = parts.join("-")
const head = "hello".slice(0, 3)
const same = "hello".substring(0, 3)
const tail = "hello".slice(-2)

Read the implementation

Connect each part of the code to the concept before you type.

1. Split into tokens

split breaks a string on a separator and returns an array of pieces.

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

2. Join with glue

join is the inverse of split: it stitches an array into one string using the given separator.

parts.join("-")

3. Substring with slice

slice(start, end) returns characters from start up to but not including end — here "hel".

"hello".slice(0, 3)

4. Substring alternative

substring gives the same "hel" for positive indices but does not accept negative ones.

"hello".substring(0, 3)

5. Negative index

A negative start counts from the end, so slice(-2) returns the last two characters, "lo".

"hello".slice(-2)

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

split, join, slice: Lesson & Practice · Typorithm | ApplyDjinn