Add splitLines

This commit is contained in:
Angelos Chalaris
2017-12-29 12:58:58 +02:00
parent 60798519a1
commit c6b1c65f14
2 changed files with 14 additions and 0 deletions

13
snippets/splitLines.md Normal file
View File

@ -0,0 +1,13 @@
### splitLines
Splits a multiline string into an array of lines.
Use `String.split()` and a regular expression to match line breaks and create an array.
```js
const splitLines = str => str.split(/\r?\n/);
```
```js
splitLines('This\nis a\nmultiline\nstring.\n'); // ['This', 'is a', 'multiline', 'string' , '']
```