Replace all "\ n" with ","

I have a text box and I want to replace "\ n" with "," in it with a value.

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

But that doesn't work? Why? Where am I mistaken?

+4
source share
2 answers

You just need to remove the quotes (otherwise it searches for this string), for example:

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

You can try here

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

Source: https://habr.com/ru/post/1314316/


All Articles