Lodash - parseInt方法



語法

_.parseInt(string, [radix=10])

將字串轉換成指定基數的整數。如果基數未定義或為0,則使用基數10,除非值是十六進位制數,在這種情況下使用基數16。

引數

  • [string=''] (string) − 要轉換的字串。

  • [radix=10] (number) − 以此基數來解釋值。

輸出

  • (number) − 返回轉換後的整數。

示例

var _ = require('lodash');
var result = _.parseInt('010');

console.log(result);

result = _.map(['6', '08', '10'], _.parseInt);
console.log(result);

將以上程式儲存在tester.js中。執行以下命令來執行此程式。

命令

\>node tester.js

輸出

10
[ 6, 8, 10 ]
lodash_string.htm
廣告
© . All rights reserved.