I want to declare a list of dictionaries where the key is a string
and the value is a number.
How might I modify the current code, see below, that declares count
as a a list of strings.
const dict: string[] = [];
dictionary where the key is a string and the value is a number.
This is a Record
type. In this case:
Record<string, number>
Or an index signature would work as well:
{ [myKey: string]: number }
Then just add a []
to the end of either of those to make it an array of those objects.
const dict: Record<string, number>[] = [
{ a: 123, b: 456 },
{ c: 789 },
]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With