如何使用map / filter / reduce组合两个数组? [英] How to combine two arrays using map/filter/reduce?
本文介绍了如何使用map / filter / reduce组合两个数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个对象阵列:员工和公司。
I have two arrays of objects: employees and companies.
var employees= [{
name: 'XYZ',
empId: 0,
age: 29,
compId: 1
}, {
name: 'ABC',
empId: 1,
age: 26,
compId: 2
}, {
name: 'EFG',
empId: 2,
age: 28,
compId: 1
}, {
name: 'MNO',
empId: 3,
age: 32,
compId: 3
}];
var companies = [{
name: 'Facebook',
id: 1
}, {
name: 'Amazon',
id: 2
}, {
name: 'Google',
id: 3
}];
通过使用基于这些数组的map / filter / reduce,我必须打印输出喜欢
32岁的员工'MNO'正在谷歌工作
这两个阵列有共同点是'employees.compId = companies.id'。
请帮助我如何关联这两个数组并打印上面的输出字符串。
By using map/filter/reduce based on these arrays, I have to print a output like
"Employee 'MNO' of Age 32 is working in Google"
These two arrays have in common is 'employees.compId = companies.id'.
Please help me how to relate these two arrays and print the above output string.
推荐答案
这里讨论你的问题 - 是否有某种方式我可以加入两个javascript数组的内容就像我会加入SQL一样 [ ^ ]。
Your question is discussed here - Is there some way I can "join" the contents of two javascript arrays much like I would do a join in SQL[^].
这篇关于如何使用map / filter / reduce组合两个数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文