diff --git a/snippets/toCharArray.md b/snippets/toCharArray.md new file mode 100644 index 000000000..e91956010 --- /dev/null +++ b/snippets/toCharArray.md @@ -0,0 +1,16 @@ +--- +title: toCharArray +tags: string,beginner +--- + +Converts a string to an array of characters. + +- Use the spread operator (`...`) to convert the string into an array of characters. + +```js +const toCharArray = s => [...s]; +``` + +```js +toCharArray('hello'); // ['h', 'e', 'l', 'l', 'o'] +```