How to replace all spaces in a string with '+' (plus sign) in JavaScript

2 Answers

0 votes
var s = 'html php css javascript';
var s = s.split(' ').join('+');

document.write(s);

/*
run: 
 
html+php+css+javascript
   
*/ 

 



answered Jun 8, 2018 by avibootz
0 votes
var s = 'html php css javascript';
var s = s.replace(/ /g, '+');

document.write(s);

/*
run: 
 
html+php+css+javascript
   
*/ 

 



answered Jun 8, 2018 by avibootz

Related questions

2 answers 280 views
1 answer 225 views
1 answer 224 views
...