Files
30-seconds-of-code/snippets/splitLines.md
Isabelle Viktoria Maciohsek 8bf67754ce Make expertise a field
2022-03-01 20:21:45 +02:00

465 B

title, tags, expertise, firstSeen, lastUpdated
title tags expertise firstSeen lastUpdated
Split into lines string,regexp beginner 2017-12-29T12:58:58+02:00 2020-10-22T20:24:30+03:00

Splits a multiline string into an array of lines.

  • Use String.prototype.split() and a regular expression to match line breaks and create an array.
const splitLines = str => str.split(/\r?\n/);
splitLines('This\nis a\nmultiline\nstring.\n');
// ['This', 'is a', 'multiline', 'string.' , '']