Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

283
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda