Try regex:

'This iS IIS'.replace(/is/ig, 'as');

Working Example: http://jsfiddle.net/9xAse/

e.g:
Using RegExp object:

    var searchMask = "is";
    var regEx = new RegExp(searchMask, "ig");
    var replaceMask = "as";
    
    var result = 'This iS IIS'.replace(regEx, replaceMask);
    
    console.log(result);
Run code snippetEdit code snippet Hide Results Copy to answer Expand

Answer from Chandu on Stack Overflow
Discussions

node.js - How can I perform a case insensitive replace in JavaScript? - Stack Overflow
I current have the following code: const pattern = "quick"; const re = new RegExp(pattern, "gi"); const string = "The quick brown fox jumped over the lazy QUICK dog"; const replaced = s... More on stackoverflow.com
🌐 stackoverflow.com
Javascript | case-insensitive string replace - Stack Overflow
javascript replace all with case insensitive and keeping correct case in original string (2 answers) More on stackoverflow.com
🌐 stackoverflow.com
February 9, 2017
Javascript Replace Making it Case Insensitive - JavaScript - SitePoint Forums | Web Development & Design Community
How do I make a Javascript replace search case insensitive? My original string contains tags which are mostly lowercase. My function that produces the search substring uses the innerHTML property and as such it automaticaly converts all tags to uppercase. So to do the search and replace correctly ... More on sitepoint.com
🌐 sitepoint.com
0
December 12, 2004
Case-insensitive string replace-all in JavaScript without a regex - Stack Overflow
I would like to do a case-insensitive string replace-all in JavaScript without using a regex (or regex-style strings in calls to the replace method). I could not find a question or answer for this,... More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › @cheezycode › how-to-replace-string-case-insensitive-in-javascript-341f63e15086
How to replace string case insensitive in JavaScript? | by CheezyCode | Medium
February 2, 2019 - This video talks about the replace function in javascript where we can replace all the occurrences of a string in a text. Many of us use this replace method wrong while writing code. It is great to replace and also has a possibility to do case insensitive replace.
🌐
C# Corner
c-sharpcorner.com › article › javascript-string-replace-case-insensitive
JavaScript String Replace | Case Insensitive
However, many of us developers use this method in the wrong way while writing the code. Here, I am showing the right way of using the .replace function in JavaScript. It is a great tool to replace the strings and also has the potential of making a case-insensitive replacement.
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-case-insensitive-replace
Replace a String case-insensitive in JavaScript | bobbyhadz
... Copied!const str = 'HELLO HELLO ... that we set the i and g flags on the regular expression. The i flag stands for ignore and does a case-insensitive search in string....
🌐
YouTube
youtube.com › watch
JavaScript String Replace | Case Insensitive - YouTube
#javascript This video talks about the replace function in javascript where we can replace all the occurrences of a string in a text. Many of us use this rep...
Published: January 27, 2019
Find elsewhere
🌐
BitDegree
bitdegree.org › learn › best-code-editor › javascript-replace-example-3
JavaScript replace: Example of a Case-Insensitive Replacement
In this JavaScript replace example, notice how a case-insensitive replacement should be applied. Learn to work with JavaScript strings without hassle!
🌐
Attacomsian
attacomsian.com › blog › string-replace-javascript
How to replace all occurrences of a string in JavaScript
October 4, 2022 - To replace all occurrences (case-sensitive) of the given value, you need to use a regular expression with global modifier (the g flag). const str = 'JavaScript is JavaScript!' const updated = str.replace(/JavaScript/g, 'Java') console.log(updated) ...
🌐
SitePoint
sitepoint.com › javascript
Javascript Replace Making it Case Insensitive - JavaScript - SitePoint Forums | Web Development & Design Community
December 12, 2004 - How do I make a Javascript replace search case insensitive? My original string contains tags which are mostly lowercase. My function that produces the search substring uses the innerHTML property and as such it automaticaly converts all tags to uppercase. So to do the search and replace correctly ...
🌐
CodeSweetly
codesweetly.com › javascript-string-replace-method
replace() JavaScript String Method – How to Replace Text Strings | CodeSweetly
"Friday, my friend, was born on Friday.".replace(/Friday/g, "Sunday"); // The invocation above will return: "Sunday, my friend, was born on Sunday." ... Let’s now see how to do a case-insensitive replacement.
🌐
DEV Community
dev.to › maafaishal › javascript-stringreplace-useful-cases-3963
JavaScript `string.replace()` useful cases - DEV Community
September 24, 2024 - You can make the replacement case-insensitive using the i flag. let str = "Hello World, World!"; let result = str.replace(/world/gi, "JavaScript") // Output: "Hello JavaScript, JavaScript!"
🌐
Javascriptreplace
javascriptreplace.com
JavaScript replace() String
The search is case sensativity and only replaces the first matching string, but case-insensitive and replacing all matching strings can also be done.
🌐
Tutorial Reference
tutorialreference.com › javascript › examples › faq › javascript-how-to-replace-string-in-case-insensitive-way
How to Replace a String Case-Insensitively in JavaScript | Tutorial Reference
Performing a case-insensitive replacement in JavaScript is a simple task that requires a regular expression. To replace all occurrences case-insensitively, use string.replace(/your-text/gi, 'replacement').
Top answer
1 of 5
2
  1. Start with an empty string and copy the original string.
  2. Find the index of the string to replace in the copy (setting them both to lowercase makes the search case-insensitive).
  3. If it's not in the copy, skip to step 7.
  4. Add everything from the copy up to the index, plus the replacement.
  5. Trim the copy to everything after the part you're replacing.
  6. Go back to step 2.
  7. Add what's left of the copy.

Just for fun I've created an interactive version where you can see the results of both a regex and indexOf, to see if escaping a regex breaks anything. The method used to escape the regex I took from jQuery UI. If you have it included on the page it can be found with $.ui.autocomplete.escapeRegex. Otherwise, it's a pretty small function.

Here's the non-regex function, but since the interactive section adds a lot more code I have the full code snippet hidden by default.

function insensitiveReplaceAll(original, find, replace) {
  var str = "",
    remainder = original,
    lowFind = find.toLowerCase(),
    idx;

  while ((idx = remainder.toLowerCase().indexOf(lowFind)) !== -1) {
    str += remainder.substr(0, idx) + replace;

    remainder = remainder.substr(idx + find.length);
  }

  return str + remainder;
}

// example call:
insensitiveReplaceAll("Find aBcc&def stuff ABCabc", "abc", "ab");

function insensitiveReplaceAll(original, find, replace) {
  var str = "",
    remainder = original,
    lowFind = find.toLowerCase(),
    idx;

  while ((idx = remainder.toLowerCase().indexOf(lowFind)) !== -1) {
    str += remainder.substr(0, idx) + replace;

    remainder = remainder.substr(idx + find.length);
  }

  return str + remainder;
}

function escapeRegex(value) {
  return value.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, "\\$&");
}

function updateResult() {
  var original = document.getElementById("original").value || "",
    find = document.getElementById("find").value || "",
    replace = document.getElementById("replace").value || "",
    resultEl = document.getElementById("result"),
    regexEl = document.getElementById("regex");

  if (original && find && replace) {
    regexEl.value = original.replace(new RegExp(escapeRegex(find), "gi"), replace);
    resultEl.value = insensitiveReplaceAll(original, find, replace);
  } else {
    regexEl.value = "";
    resultEl.value = "";
  }


}

document.addEventListener("input", updateResult);
window.addEventListener("load", updateResult);
<link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css" rel="stylesheet" />

<div class="input-group input-group-sm">
  <span class="input-group-addon">Original</span>
  <input class="form-control" id="original" value="Find aBcc&def stuff ABCabc" />
</div>

<div class="input-group input-group-sm">
  <span class="input-group-addon">Find</span>
  <input class="form-control" id="find" value="abc" />
</div>

<div class="input-group input-group-sm">
  <span class="input-group-addon">Replace</span>
  <input class="form-control" id="replace" value="ab" />
</div>

<div class="input-group input-group-sm">
  <span class="input-group-addon">Result w/o regex</span>
  <input disabled class="form-control" id="result" />
</div>

<div class="input-group input-group-sm">
  <span class="input-group-addon">Result w/ regex</span>
  <input disabled class="form-control" id="regex" />
</div>

2 of 5
2

The approved solution calls toLowerCase inside the loop which is not efficient.

Below is an improved version:

function insensitiveReplaceAll(s, f, r) {
  const lcs=s.toLowerCase(), lcf = f.toLowerCase(), flen=f.length;
  let res='', pos=0, next=lcs.indexOf(lcf, pos);
  if (next===-1) return s;
  
  do {
    res+=s.substring(pos, next)+r;
    pos=next+flen;
  } while ((next=lcs.indexOf(lcf, pos)) !== -1);
  
  return res+s.substring(pos);
}

console.log(insensitiveReplaceAll("Find aBc&deF abcX", "abc", "xy"));
console.log(insensitiveReplaceAll("hello", "abc", "xy"));

Testing with jsPerf - https://jsperf.com/replace-case-insensitive-2/1 - shows it to be 37% faster.

🌐
The Web Dev
thewebdev.info › home › how to do a case insensitive replace all with a javascript string?
How to Do a Case Insensitive Replace All with a JavaScript String? - The Web Dev
August 6, 2021 - The g flag lets us search for all instances of the regex pattern. As a result, str is 'Thas as Ias’ . To do a Case insensitive replace all with JavaScript string, we can use a regex to do the replacement.
🌐
Adobe Support Community
community.adobe.com › home › app communities › photoshop › questions › sdk javascript replace ignore case string
SDK Javascript replace ignore case string | Community
November 20, 2021 - Hey Every tutorial/info I find usually uses "modern" javascript, but since PS is rocking one from 1990... I have no idea how to do it :- ) Can any1 let me know how to do a string replace? var key = "hello" var value = "Hello World" var final = "Nice" value.replace(/key/gi,final) does n...