String to character array

OSCC · JavaScript, String · Oct 8, 2020

Converts a string to an array of characters.

  • Use the spread operator (...) to convert the string into an array of characters.
const toCharArray = s => [...s];
toCharArray('hello'); // ['h', 'e', 'l', 'l', 'o']

Recommended snippets

  • CSV to JSON

    JavaScript, String

    Converts a comma-separated values (CSV) string to a 2D array of objects. The first row of the string is used as the title row.

  • Swapcase string

    JavaScript, String

    Creates a string with uppercase characters converted to lowercase and vice versa.

  • HSL to array

    JavaScript, String

    Converts an hsl() color string to an array of values.