2
Answers

Split newline string using comma

Vignesh Kumar

Vignesh Kumar

10y
1.5k
1
Hi,
I need a javascript to split newline characters with commas. The below one, I am able to split white space and not the new line. Can anyone help me?
  <html>
  <head>
  <script>
  function convert() {
  var data = document.getElementById("get").value;
  var lines = data.split(' ');
  document.getElementById("display").value = lines.join(',');
  }
  </script>
  </head>
  <body>
  <div>
  Enter Code:
  </br>
  <textarea id="get"> </textarea>
  </br>
  <input type="button" value='Convert' onclick="convert()"/>
  </br>
  <textarea id="display"> </textarea>
  </div>
  </body>
  </html>



Answers (2)