Big Smile
Big Smile

Reputation: 1124

How to convert an array of integers to a single digit

let's say I have got an array of [2, 4, 5, 6].

I want to be able to convert it to 2456.

Is there an easy and elegant way to do this in JavaScript?

I am aware of this question.

Upvotes: 1

Views: 735

Answers (1)

Majed Badawi
Majed Badawi

Reputation: 28414

Using Array#join:

const arr = [2, 4, 5, 6];

const str = arr.join('');

console.log('string', str);
console.log('number', +str);

Upvotes: 1

Related Questions