How can I apply an array to a lookup dictionary in Javascript? Example:
lookup = {"milk": 1, "water": 2, "soda": 3};
my_array = ["milk", "milk", "water", "milk", "soda"];
my_array.??? // This should give [1, 1, 2, 1, 3]
I've tried my_array.map(lookup)
and I get #<Object> is not a function
. Same with .filter()
, .apply()
and the other obvious candidates.