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

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

πŸ“– 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()

str.split(separator) splits the string into an array of substrings at each separator.

Challenge: Implement splitByComma(str) that splits a comma-separated string.

splitByComma('a,b,c') // β†’ ['a', 'b', 'c']
πŸ’‘ Hints (1)
  • β€’ `str.split(",")` splits at every comma.