To replace substring.But not working for me...
var str='------check';
str.replace('-','');
Output: -----check
Jquery removes first '-' from my text. I need to remove all hypens from my text. My expected output is 'check'
To replace substring.But not working for me...
var str='------check';
str.replace('-','');
Output: -----check
Jquery removes first '-' from my text. I need to remove all hypens from my text. My expected output is 'check'
Try this instead:
str = str.replace(/-/g, '');
.replace() does not modify the original string, but returns the modified version.
With the g at the end of /-/g all occurences are replaced.
' for this to work :-) (Also, it's not necessary to escape the hyphen, which has no special meaning outside of a character class).