Lodash教程

Lodash parseInt method

语法

_.parseInt(string, [radix=10])
Converts string to an integer of the specified radix. If radix is undefined or 0, a radix of 10 is used unless value is a hexadecimal, in which case a radix of 16 is used.

参数

[string=''] (string) − The string to convert. [radix=10] (number) − The radix to interpret value by.

输出

(number) − Returns the converted integer.

实例

var _ = require('lodash');
var result = _.parseInt('010');
console.log(result);
result = _.map(['6', '08', '10'], _.parseInt);
console.log(result);
Save the above program in tester.js. Run the following command to execute this program.

Command

\>node tester.js

输出

10
[ 6, 8, 10 ]
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4