如何根据属性匹配来自不同对象数组的值?

时间:2019-06-08 00:44:03

标签: javascript arrays object

我有两个单独的对象数组。如何将一个对象数组中的属性与第二个数组中的另一个属性进行匹配?

我需要将const cars中的汽车用途const buyers中的 searchingUse 进行匹配。

const cars = [
{ model:convertible,
  year:2015,
  use:sports
},
{ model:wagon,
  year:2013,
  use:family
}
]

const buyers =[
{  name:John
   searchingUse: family,
   maxYear: 2014,
   maxPrice:15000

},
{  name: Mark
   searchingUse: sedan,
   maxYear: 2012,
   maxPrice:1000

}
]

预期输出将是一个字符串,其中列出与使用

所需的每个买家匹配的所有汽车。

非常感谢您的帮助!

谢谢

1 个答案:

答案 0 :(得分:0)

我认为您想要这样的东西:

2019-06-07 14:20:46.169 (963    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000
2019-06-07 14:20:46.169 (963    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=10.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000
2019-06-07 14:20:46.272 (963    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=5.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000
2019-06-07 14:20:46.272 (963    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=5.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000
2019-06-07 14:20:48.195 (966    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=11.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000
2019-06-07 14:20:48.195 (966    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=normal:stretch=normal:size=11.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono.ttf') with score of 0.050000
2019-06-07 14:20:49.686 (967    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=bold:stretch=normal:size=22.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf') with score of 0.000000
2019-06-07 14:20:49.686 (967    MB) DEBUG [23116| font_manager.findfont]: findfont: Matching :family=DejaVu Sans Mono:style=normal:variant=normal:weight=bold:stretch=normal:size=22.0 to DejaVu Sans Mono (u'/local/lib/python2.7/site-packages/matplotlib/mpl-data/fonts/ttf/DejaVuSansMono-Bold.ttf') with score of 0.000000