When working with TypeScript, I encountered an issue with using an array as a map to access another array of objects. Below is a simplified snippet of my code:
var mp : Number[] = [1, 2, 0];
var arr : any[] = ['a', 4, /regex/];
console.log(arr[mp[2]])
Upon running this code, I received the following error message:
Error TS2538: Type 'Number' cannot be used as an index type.
I have searched for solutions but most do not address such a straightforward scenario involving an array and a Number
. Is there a different way to index an array without using a Number
object?