js中string轉int和int轉string

1.string轉int

1.1使用parseInt方法

var a = '123';
console.log('a==>' + typeof a);
var b = parseInt(a);
console.log('b==>' + typeof b);

運行結果:

2.int轉string

2.1使用toString(方法)

var a = 123;
console.log('a==>' + typeof a);
var b = a.toString();
console.log('b==>' + typeof b);

運行結果:

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章