Replace all spaces in a string with ‘+’

Here’s an alternative that doesn’t require regex:

var str = 'a b c';
var replaced = str.split(' ').join('+');

Leave a Comment