Home > Software design >  How to convert a string (button) to number in JavaScript
How to convert a string (button) to number in JavaScript

Time:11-16

How to convert a string to an integer in JavaScript?

const secrectNumber = 4;

button >01</button

button >02</button

button >03</button

button >04</button

button >05</button

$(".btn-number").click(function (e) {
   if ($(this).text() === secretNumber) {
       
   }

}

How do I convert button is string to number in JavaScript?

CodePudding user response:

parseInt will turn string into int

parseInt('1') = 1

CodePudding user response:

You can convert a string to an integer either by using the Number wrapper, like so:

Number('01') // Returns 1

Or by using parseInt and passing a radix parameter. Assuming you're working in base-10:

parseInt('11', 10) // Returns 11.

Not too sure what you mean by 'How do I convert button is string to number in JavaScript?'

Could you elaborate?

  • Related