I have an array contains two elements [0010, 0011]; like this. i need the same two elements in the output also.
var a = [0010, 0011];
for (var i=0;i<a.length;i++){
console.log(a[i]); // output is 8, 9 (expected output 0010,0011)
}
I have an array contains two elements [0010, 0011]; like this. i need the same two elements in the output also.
var a = [0010, 0011];
for (var i=0;i<a.length;i++){
console.log(a[i]); // output is 8, 9 (expected output 0010,0011)
}
You can convert the numbers to strings for display using the toString function.
console.log(a[i].toString(8)); // displays in base 8 (octal)
This way they stay in numeric form in your array, so you can still do math operations on them.
Use String as javascript interprets numeric constants as octal.
var a = ["0010", "0011"];
for (var i=0;i<a.length;i++){
console.log(a[i]); // expected output 0010,0011
}