-1

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

gvlasov
  • 16,604
  • 19
  • 65
  • 103

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
  • 25,851
  • 7
  • 65
  • 105
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
  • 329
  • 2
  • 5