I am trying to implement code that will return me a random element of a dictionary in TypeScript. So far, I've tried this:
dict = {
0: "example 1",
1: "example 2",
2: "example 3"
}
randomGen() {
var num = Math.floor(Math.random() * (3));
console.log(this.dict[num])
}
However this is throwing me an error:
Element implicitly has an 'any' type because expression of type 'number' can't be used to index type '{ 0: string; 1: string; 2: string; }
Is there a way around this? How can I randomly select an element from my dictionary?