New snippet - changeStringToArrayOfChars

This commit is contained in:
Bartek Tomiak
2020-10-07 21:51:13 +02:00
parent 5169b41c1b
commit 1c6967719b

View File

@ -0,0 +1,20 @@
---
title: changeStringToArrayOfChars
tags: array,intermediate
---
Function takes string as a parameter and returns an array of characters.
- Array.prototype.split() divides a given string to separate characters
- In this case `split()` takes in an empty string as an argument `str.split('')`
- Separator can be a string or a regural expression
```js
const changeStringToArrayOfChars = text => {
return text.split('');
}
```
```js
changeStringToArrayOfChars('jsisawesome'); // ["j", "s", "i", "s", "a", "w", "e", "s", "o", "m", "e"]
```