Mohan Ram Mohan Ram - 13 days ago 6
Javascript Question

How to replace substring in Javascript?

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'

Answer

simplest:

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