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

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

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 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!