Skip to main content
Solved

How to split multiline text into an array?

  • January 14, 2021
  • 1 reply
  • 14 views

Kim_Trager1
Forum|alt.badge.img+23

I have some multiline text I for some reason do not seem to be able to split into parts.

My text is:
“506070
80”

let arr = multi.toString().split(" ");
console.log(arr) //["506070 80"]

Does anyone know how I can split this?
If i make real space in the multiline text it splits as expected.

Best answer by Kim_Trager1

for anyone need to do the same I figured it out.

let arr = multi.replace(/(\r\n)|\r|\n/g, '\n').split(/\n+/g);

1 reply

Kim_Trager1
Forum|alt.badge.img+23
  • Author
  • Brainy
  • 168 replies
  • Answer
  • January 14, 2021

for anyone need to do the same I figured it out.

let arr = multi.replace(/(\r\n)|\r|\n/g, '\n').split(/\n+/g);