Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

110
Views
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?

about 4 years ago · Santiago Gelvez
2 answers
Answer question

0

That's not how you index a 2-dimensional array (well, array of arrays; there are no 2-dimensional arrays in JavaScript).

You're looking for dataArr[j][k], not dataArr[j,k].

[j, k] evaluates to just k since the comma is parsed as the comma sequence operator; j is evaluated and thrown away, and k is the result. It is then used to index the top-level dataArr, and indeed, replaceAll is not a method on the arrays nested within.

You could also rewrite this as a double map and use a regexp so you don't need to spell out all of those replacements:

dataArr = dataArr.map(row => row.map(c => String(c).replace(/[":ILS}]+/g, "")));
about 4 years ago · Santiago Gelvez Report

0

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

about 4 years ago · Santiago Gelvez Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!