-1

In my html page I have to split user input based on newline character. How to get newline character using javascript?

gvlasov
  • 18,638
  • 21
  • 74
  • 110

2 Answers2

0

The resume of possible duplicate is using regex does allow you to ignore the OS you're using:

I don't think you really need to do much of any determining, though. If you just want to split the text on newlines, you could do something like this:

lines = foo.value.split(/\r\n|\r|\n/g);

In your case:

var splittedValues = originalTxt.split(/\r\n|\r|\n/g);
Community
  • 1
  • 1
Jordi Castilla
  • 26,609
  • 8
  • 70
  • 109
0

Please see the below code :

var str=document.getElementById('nwline').value;

var lines = str.split(/\r\n|\r|\n/g);

console.log(lines);

http://jsfiddle.net/asimshahiddIT/0yog7v83/

asimshahiddIT
  • 330
  • 2
  • 5