#dictionary comprehension like in python
1 messages · Page 1 of 1 (latest)
"comprehension" exists in very few languages afaik
assuming you have an array, you could use Object.fromEntries(arr.map(...)) basically
and within map you'd have a callback turning each object into [name, 0]
you could also use arr.reduce to build that object gradually
or just use a normal loop to do the same as reduce
multipliers: {[key: string]: number} = Object.fromEntries(listOfFood.map(food => [food.Name, 0]))
``` should work?
!resolved