-2

I want to remove all "0" in my string, not only the first same value, any suggest?

Why its work but just only the first code

var str = "90807005"

console.log(str.replace("0",""))

I try to read another source and say to use (/"something"/g, new) for change all same value, and its still not working

var str = "90807005"

console.log(str.replace(/"0"/g,""))

I want it to be str = "9875";

1 Answers1

0

You can use String.replaceAll or a global flag in your regex:

var str = "90807005"

console.log(str.replaceAll("0","")) //replaceAll
console.log(str.replace(/0/g,"")) //global flag
Spectric
  • 30,714
  • 6
  • 20
  • 43