A
A
Alexey2020-05-06 00:05:10
JavaScript
Alexey, 2020-05-06 00:05:10

How to convert a large array of numbers to a single number?

Let's say it has an array like this:
let array = [9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5 , 6,7,7];
How can it be converted to a single number? - 9223372036854775677
Is there any shorthand method to implement this question? It didn’t work through Number, because it has limitations. It’s possible through BigInt, but I still haven’t figured out how to implement it.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2020-05-06
@alekseyy__9090

The fact is that

console.log(Number.MAX_SAFE_INTEGER)
//9007199254740991

That is, you do not fit into integer, so you need to use BigInt
const array = [9, 2, 2, 3, 3, 7, 2, 0, 3, 6, 8, 5, 4, 7, 7, 5 , 6,7,7];
const number = BigInt(array.join(''));
console.log(number.toString());

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question