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

162
Visualizações
How to convert from String to the other data type where the data type is stored in a variable - JAVASCRIPT

I have a requirement to convert from String to the multiple other data types dynamically in Javascript. The datatype name is stored in a variable.

For example

let dt = 'Integer';
let toConvert = '1';
//I want to convert the 'toConvert' string to an Integer

How do i do this dynamically as dt can change based on scenarios.

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

So what you probably want to do my guy is use the parseint method. This will take a string variable and return a number.

  const string = '10s123dqwd'
  console.log(parseInt(string))

   //or you could write
   const number = parseInt(string)
   console.log(number

//output = 10123

This method also removes any chars from the string as well.

If you are interested in reading more on this topic there is an article which takes an in depth look at multiple methods of converting java script strings into numbers here https://dev.to/sanchithasr/7-ways-to-convert-a-string-to-number-in-javascript-4l

about 4 years ago · Santiago Gelvez 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