You can do it in several ways:
By using the Number function
var i=Number(“100”);
parseInt:
var i=parseInt(“100”,10)->10 means decimal
Unary plus:
var i=+”100”;
If your string might be a float and you want a integer:
var i=Math.floor(“100.01”);
Or
var floor=Math.floor;
var i=floor(“100.01”);
You can use parseFloat:
var floor=Math.floor;
var i=floor(parseFloat(“100.23”));
Math.out like this:
var round=Math.round;
var i=round(“100”);
Want to be a full stack developer? Check out the Full stack developer course from Intellipaat.