JS Built-ins
← String129 / 195
StringString.prototype.splitbeginner

String.prototype.split() β€” empty string gives chars array

πŸ“– Usage Example
'a,b,c'.split(',')    // β†’ ['a', 'b', 'c']
'hello'.split('')     // β†’ ['h', 'e', 'l', 'l', 'o']
'hi'.split()          // β†’ ['hi']

Use split() to divide a string into an array of substrings at each occurrence of the separator.

String.prototype.split() β€” Empty Separator

Splitting on an empty string '' splits the string into individual characters.

Challenge: Implement toChars(str) that returns an array of characters.

toChars('hello') // β†’ ['h', 'e', 'l', 'l', 'o']
πŸ’‘ Hints (1)
  • β€’ `str.split("")` splits at every character boundary.