Merge pull request #1408 from bartomiak/master
New snippet - toCharArray
This commit is contained in:
16
snippets/toCharArray.md
Normal file
16
snippets/toCharArray.md
Normal file
@ -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']
|
||||||
|
```
|
||||||
Reference in New Issue
Block a user