In TypeScript, I have an array that I am using like a map to access another array of objects. Here is an extremely simplified example of my code:
var mp : Number[] = [1, 2, 0];
var arr : any[] = ['a', 4, /regex/];
console.log(arr[mp[2]])
However, running this yields:
error TS2538: Type 'Number' cannot be used as an index type.
I've looked elsewhere but the other answers for this type of error don't pertain to something as simple as an array and a Number
. If not a Number
object, how can I index an array?