I have an array. As far as I know array keys are integers in javascript.
const array1 = ['a', 'b', 'c'];
When I get and log keys I get an array of integers.
console.log([...array1.keys()]);
// Outputs=> [0, 1, 2]
But in a for...in loop keys are string. But why and is there a way to type cast for integer keys?
for (const key in array1) {
console.log("Type of key "+key+" is "+ typeof key);
}
/* outputs:
Type of key 0 is string
Type of key 1 is string
Type of key 2 is string
*/