Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

replace/replaceAll is not a function

I’m trying to use replace in order to remove some characters in a 2d array of strings, but I keep incountering an issue:

      dataArr[j,k] = dataArr[j,k].replaceAll(mCH, "");
                              ^

TypeError: dataArr[(j , k)].replaceAll is not a function
at Object.<anonymous> (C:\Users\magshimim\say-hi-to-sheli-from-me\rafaels-crypto-ninja\thingy\server\index.js:45:35)
at Module._compile (node:internal/modules/cjs/loader:1105:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1159:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:77:12)
at node:internal/main/run_main_module:17:47

this is the part of my code using the function:

for (let j = 0; j < dataArr.length; j++)
{
  for (let k = 0; k < dataArr[j].length; k++)

  {
      dataArr[j][k] = dataArr[j][k].replaceAll('"', "");
      dataArr[j][k] = dataArr[j][k].replaceAll(":", "");
      dataArr[j][k] = dataArr[j][k].replaceAll("I", "");
      dataArr[j][k] = dataArr[j][k].replaceAll("L", "");
      dataArr[j][k] = dataArr[j][k].replaceAll("S", "");
      dataArr[j][k] = dataArr[j][k].replaceAll("}", "");
  }
}

Do I need to download anything? maybe there’s a problem with my code?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use the .replace function instead of replaceAll, if the later is not available.

"any string".replace(new RegExp("to replace", "g"), "new text")

This is by using new RegExp("text to replace", "g") as a string to search

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading