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

String.prototype.split() β€” split by string

πŸ“– 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() β€” String Separator

The separator can be a multi-character string.

Challenge: Implement splitBySep(str, sep) that splits str by the separator sep.

splitBySep('one::two::three', '::') // β†’ ['one', 'two', 'three']
πŸ’‘ Hints (1)
  • β€’ The separator can be any string, not just a single character.