Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

156
Visualizações
Cannot read property 'replace' of null when turning a string value into Number

Hey im trying to convert a string that holds numbers but the string has commas in it and I'm trying to remove those commas as well.

let why = "42,343,324"
console.log(typeof why) // string
let noCommas = parseFloat(why.replace(/,/g, ''));
console.log(noCommas) // 42343324

but when I replace why value with a prop value, it gives me an error saying Cannot read property 'replace' of null

let why = visitsPerPerson
console.log(typeof why)
let noCommas = parseFloat(why.replace(/,/g, ''));
console.log(noCommas)

Output: Cannot read property 'replace' of null

The prop is a string value that holds numbers returned from an API the prop itself doesn't return null but returns a string with numbers in it and can verify when I console log: console.log(visitsPerPerson)

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

I re-produced the second code snippet and got expected output:

NaN (Not a Number), which is correct and the expected result for "visitsPerPerson".

Did I understand something wrong?

let why = "visitsPerPerson";
console.log(typeof why); // string
let noCommas = parseFloat(why.replace(/,/g, ''));
console.log(noCommas); // NaN (Not a Number, which is correct)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda