I want to create an integer or number that contains all the digits from an array of digits or string. How can I achieve that ?
for example:
digitArry = [9', '8', '7', '4', '5', '6'];
should become
integer = 987456;
You can use join and parseInt:
var digitArry = ['9', '8', '7', '4', '5', '6'];
var integer = parseInt(digitArry.join(''), 10);
console.log(integer);
EDIT: As suggested by @kay, another alternative is using + to convert string to number:
var digitArry = ['9', '8', '7', '4', '5', '6'];
var integer = +digitArry.join('');
console.log(integer);
10 as the baseparseInt, since some browser do not use the base 10 by default.parseInt without specifying the radix. Almost always +str is the better alternative.0
num = Number(digitArry.join(""));['95', '3']or['9', '000001']?