17 lines
287 B
Markdown
17 lines
287 B
Markdown
---
|
|
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']
|
|
```
|