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

171
Vistas
Convert string of character and number into integer?

I want to convert this string "F1" into an integer 1.

For example

"F1" ===> 1
"F2" ===> 2
"F3" ===> 3

So far, this is what I've done

parseLevel: function(level) {
    var levels = {
        "F1": 1,
        "F2": 2
    };
    return levels[level];
}

Here's the function

parseLevel: function (level) {
  return parseInt(level, 10);
}

I'm getting an error says it's NaN

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Since the string you pass has a leading F in it; parseInt can't figure out what integer F1 could be so just strip the F of the string.

parseLevel: function (level) {
  return parseInt(level.slice(1), 10);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

Here is an example of how you could parse any string and only use its digits. to parse an integer.

let s = "ajs382bop";//can be any string it will strip all non digits
function stripAndReturnNumber(s){
    return parseInt(s.replace(/\D/g, ""));
    //This will replace all non digits with nothing and leave all digits remaining.
    //Then it will return the resulting integer.
}
console.log(stripAndReturnNumber(s));//382
about 4 years ago · Juan Pablo Isaza Denunciar
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