1. Split into tokens
split breaks a string on a separator and returns an array of pieces.
"a,b,c".split(",")Typorithm · easy
Step 1 of 8 · intro card
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.
split breaks a string into an array of tokens.
join glues an array into a string.
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)Connect each part of the code to the concept before you type.
split breaks a string on a separator and returns an array of pieces.
"a,b,c".split(",")join is the inverse of split: it stitches an array into one string using the given separator.
parts.join("-")slice(start, end) returns characters from start up to but not including end — here "hel".
"hello".slice(0, 3)substring gives the same "hel" for positive indices but does not accept negative ones.
"hello".substring(0, 3)A negative start counts from the end, so slice(-2) returns the last two characters, "lo".
"hello".slice(-2)Read the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.