How we can delete some special character from a string by javascript
2 Answers
The best way is to replace it, either using a string or regular expression.
String:
// JavaScript Document
var string = 'Hello world!';
alert( string.replace( 'world', '' ) ); // Alerts "Hello !"
Regular Expression:
// JavaScript Document
var string = 'Hello world!';
alert( string.replace( /o/, '' ) ); // Alerts "Hell wrld!"
3 Comments
Kerry Jones
@Arpan Steve314 is right, though I've never seen the
.replace used directly on a string. /[how]/ is the regular expression you want.