I have an array of numbers and some of them has leading zeros. How can I make them to string without losing leading zeros?
var array = [10, 00002, 30, 400, 5000];
array[1].toString; // would be 2 instead of 0002 as JS drops leading zeros
I have looked other solutions (JavaScript Number preserve leading 0, JavaScript: Keeping the leading zero in a number and JavaScript Number preserve leading 0), and they all suggest to make the number string.
But in my case the numbers in array would be provided by user, so when they're go through .toString they lose leading zeros.
How can I get around this so when I slice the first 2 digits of each elements they final array would be:
var twoDigitArray = ["10", "00", "30", "40", "50"];
?