JS Built-ins
ArrayArray.frombeginner

Array.from() β€” convert a string to chars

Array.from()

Array.from() creates a new array from an iterable or array-like object. Since strings are iterable in JavaScript, you can use Array.from() to split them into individual characters.

Challenge: Implement stringToChars using Array.from() to convert a string into an array of its characters.

stringToChars('hello') // β†’ ['h', 'e', 'l', 'l', 'o']
stringToChars('')      // β†’ []
πŸ’‘ Hints (2)
  • β€’ Strings are iterable β€” Array.from() works on any iterable.
  • β€’ Array.from(someString) iterates over each character.