Use parseInt:
var myString = "34";
var myIntegerFromString = parseInt(myString); // 34 (integer)
console.log("myString ");
console.log(myString); // 34
console.log(typeof myString); //string
console.log("myIntegerFromString ");
console.log(myIntegerFromString); // 34
console.log(typeof myIntegerFromString); //integer
Resource:
http://www.javascripter.net/faq/convert2.htm
http://www.javascriptkit.com/javatutors/determinevar2.shtml
var myString = "34";
var myIntegerFromString = parseInt(myString); // 34 (integer)
console.log("myString ");
console.log(myString); // 34
console.log(typeof myString); //string
console.log("myIntegerFromString ");
console.log(myIntegerFromString); // 34
console.log(typeof myIntegerFromString); //integer
Resource:
http://www.javascripter.net/faq/convert2.htm
http://www.javascriptkit.com/javatutors/determinevar2.shtml
No comments:
Post a Comment