主题
parseInt
js
_.parseInt(string, [radix=10])将 string 转换为指定基数的整数。如果 radix 是 undefined 或 0,则使用 10 的 radix,除非 value 是十六进制,在这种情况下使用 16 的 radix。
¥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.
注意:此方法与 parseInt 的 ES5 实现 一致。
¥Note: This method aligns with the ES5 implementation of parseInt.
新增于
¥Since
1.1.0
参数
¥Arguments
string(字符串):要去毛刺的字符串。¥
string(string): The string to convert.[radix=10](数值):用于解释value的基数。¥
[radix=10](number): The radix to interpretvalueby.
返回
¥Returns
(数值):返回转换后的整数。
¥(number): Returns the converted integer.
示例
¥Example
js
_.parseInt('08');
// => 8
_.map(['6', '08', '10'], _.parseInt);
// => [6, 8, 10]