Javascript string replace (all occurrences)

/ Published in: JavaScript
Save to your folder(s)

Copy this code and paste it in your HTML
  1. //replace all whitespaces with underscore
  2. string.replace(new RegExp(/\s/g), '_');
  4. //replace the word 'replace' with 'replaced'
  5. string.replace(/replace/g, 'replaced');

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.