Code Premix

Replace multiple strings using Split and Join functions

📅June 11, 2021

Today we will show you how to replace multiple strings in JavaScript using Split and Join functions. In the previous article, we explained how to replace multiple strings using Regular Expression.

Use the following code to replace multiple strings using Split and Join method.

function handleReplaceAllSplitJoin() {
  var sentence = 'This is test example and it Is easy to learn.';
  var output = sentence.split('is').join('-'); // Output: Th- - test example and it Is easy to learn.
  document.getElementById("demo2").innerHTML = output;
}

That’s it for today.