Replace all "\n" with ","

13,382

Solution 1

You just need to remove the quotes (otherwise it's looking for that string), like this:

var valuetxtarr = $("#txtarr").val();
var valuetxtarrs = valuetxtarr.replace(/\n/g,",");
alert(valuetxtarrs);​

You can give it a try here

Solution 2

var valuetxtarr = $("#txtarr").val(); 
var valuetxtarrs = valuetxtarr.replace(/\n/g,","); 
alert(valuetxtarrs);
Share:
13,382
Admin
Author by

Admin

Updated on July 23, 2022

Comments

  • Admin
    Admin almost 2 years

    I have a textarea and I want to replace "\n" with "," in it's value.

    var valuetxtarr = $("#txtarr").val();
    var valuetxtarrs = valuetxtarr.replace("/\n/g",",");
    alert(valuetxtarrs);
    

    But it don't work?Why?Where I have mistake?

  • jigfox
    jigfox almost 14 years
    @lam3r4370 you should accept an answer when it is resolving your problems.
  • Nick Craver
    Nick Craver almost 14 years
    @Jens - He can't for about 15 minutes after asking...it was a throttle set to encourage more answers a while back :)