Cress
Cress

Reputation: 432

Convert array of strings to one integer

do you know how to convert an array of strings to one integer?

Example:

var array = ["1","2","3","4"];

to

var number = 1234;

Upvotes: 2

Views: 82

Answers (1)

Rob M.
Rob M.

Reputation: 36511

Here you go, just need to join the array and parse the integer out:

var array = ['1', '2', '3', '4'];
var number = parseInt(array.join(''), 10);
alert(number);

Note: The 10 used in the parseInt function above is to specify the radix (also known as the base in mathematical numeral systems). 10 signifies the base used in decimal system.

Upvotes: 7

Related Questions