Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

170
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!