0

I have an array and I need to get some data by array values.

let array = ["Clothing", "Home", "Payments"];
const expenses = {
  clothing: '#FF9494',
  food: '#0099CC',
  healthCare: '#C58BE2',
  home: '#FF8A00',
  recreation: '#669900',
  payments: '#CC0D01',
};

I need to get an array of object values

['#FF9494', '#FF8A00', '#CC0D01']

array.map(el => {
  let target = expenses.map(obj => obj === el);
  return target;
})
Sasha Zoria
  • 739
  • 1
  • 9
  • 28
  • (1) You'd need to convert your array of the properties you want to actual property names (in this case, lower-casing is sufficient), then (2) map over those keys and get the values using bracket notation. What's the specific issue? – Dave Newton Aug 13 '19 at 13:47

1 Answers1

2

Expenses is an object, that means that you can look up properties by key:

 array.map(key => expenses[key.toLowerCase()])
Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151