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

301
Visualizações
Determine if string is string, int, or float

All of my inputs are strings. I want to export them to a sort of DB, using the correct type.

So I can have inputs like e.g. "hello123", "123", or "123.0".
Which have the type string, int, and float respectively.

I already have a decent function determining whether it's a number or not:

const isNumber = (input) => !isNaN(Number(input))

console.log(isNumber("123hello")) // false
console.log(isNumber("123"))      // true
console.log(isNumber("123.0"))    // true

But I would like something like:

const getType = (input) => {
  if (/* check if int */) {
    return 'int'
  } else if (/* check if float */) {
    return 'float'
  } else {
    return 'string'
  }
}

console.log(getType("123hello")) // 'string'
console.log(getType("123"))      // 'int'
console.log(getType("123.0"))    // 'float' (preferably, but 'int' is also ok)
about 4 years ago · Juan Pablo Isaza
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