Lodash - parseInt method



Syntax

_.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.

Arguments

  • [string=''] (string) − The string to convert.

  • [radix=10] (number) − The radix to interpret value by.

Output

  • (number) − Returns the converted integer.

Example

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

Output

10
[ 6, 8, 10 ]
lodash_string.htm
Advertisements