Javascript String replace substring

Introduction

The following code replaces a substring within a string.

It will replace both individual characters and substrings.

// Replaces oldS with newS in the string fullS
function replaceString(oldString, newString, fullS) {
  return fullS.split(oldString).join(newString)
}

replaceString('test', 'Test', 'this is a test')



PreviousNext

Related