通过数组中的值从对象中获取值

时间:2019-08-13 13:44:35

标签: javascript arrays

我有一个数组,我需要按数组值获取一些数据。

"GET /git/repo.git/info/refs?service=git-upload-pack HTTP/1.1" 200 660 "-" "git/2.7.4"
"POST /git/repo.git/git-upload-pack HTTP/1.1" 200 8149 "-" "git/2.7.4"

我需要获取一个对象值数组

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

1 个答案:

答案 0 :(得分:2)

费用是一个对象,这意味着您可以通过键查找属性

 array.map(key => expenses[key.toLowerCase()])