Remove semicolon in string using javascript

How to remove semicolon ( ;) from string using JavaScript?

For instance:

var str = '<div id="confirmMsg" style="margin-top: -5px;">'

How to remove semicolon from str?

+3
source share
5 answers

You can use the method replacefor a string object. Here's what W3Schools says about it: JavaScript replace () .

In your case, you can do something like the following:

str = str.replace(";", "");

You can also use regex:

str = str.replace(/;/g, "");

This will replace all semicolons globally. If you want to replace only the first instance, you will remove gfrom the first parameter.

+11
source

Try the following:

str = str.replace(/;/g, "");

str str.

+6

, , :

, , ( ):

'<div id="confirmMsg" style="margin-top: -5px; margin-bottom: 5px;">'

 str.replace(";", "");

:

'<div id="confirmMsg" style="margin-top: -5px margin-bottom: 5px">'

.

:

 str.replace(";\"", "\"");

; " .

, . - , - . , , .

+6
str = str.replace(";", "");
+2

Try:

str = str.replace(/;/ig,'');
0

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


All Articles