Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace angle brackets in Javascript string? [duplicate]

Hi I have a string like below:

 >123456<

How can I easily replace the angle brackets and replace them with blank?

I have tried the below:

                        mystring.replace(/>/g, "");
                        mystring.replace(/</g, "");

However if I do an alert(mystring); on this it is still showing with the angle brackets?

like image 411
Ctrl_Alt_Defeat Avatar asked Dec 04 '22 12:12

Ctrl_Alt_Defeat


1 Answers

You need to assign, in this case, mystring with the result of the operation.

var s = '>123456789<';
s = s.replace(/[<>]/g, '');
alert(s);
like image 76
Leonard Avatar answered Jan 24 '23 12:01

Leonard