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

String.prototype.split() β€” no separator returns whole string in 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() β€” No Separator

Calling .split() without arguments returns the whole string wrapped in an array.

Challenge: Implement wrapInArray(str) that returns [str] using split().

wrapInArray('hello') // β†’ ['hello']
πŸ’‘ Hints (1)
  • β€’ `str.split()` with no argument returns `[str]` β€” the whole string as a single element.