Back
Below is the code I’ve which replaces the multiple spaces with ‘+’.
var str = 'a b c';var replaced = str.replace(' ', '+');
var str = 'a b c';
var replaced = str.replace(' ', '+');
It works only for the first occurrence. Can anyone tell me how to replace it for all?
Check the code below:
var str = 'a b c';var replaced = str.split(' ').join('+');
var replaced = str.split(' ').join('+');
Interested in Java? Check out this Java Certification by Intellipaat.
31k questions
32.8k answers
501 comments
693 users