【发布时间】:2021-09-22 19:03:34
【问题描述】:
我想要实现的是将信息从一个对象数组带到另一个对象数组,找到卡片的最后 4 个数字的匹配项,从该数组中提取具有值的键并将它们带到其他对象数组。
const array1 = [
{
card: {
expiryDate: '2025-06-30',
isPinSet: true,
issuedDate: '2021-06-02',
lastNumbers: '2377',
status: 'ACTIVE',
type: 'PHYSICAL'
}
},
{
card: {
expiryDate: '2024-11-30',
isPinSet: true,
issuedDate: '2020-12-14',
lastNumbers: '7231',
status: 'TERMINATED',
type: 'PHYSICAL',
terminationDate: '2021-06-02'
}
}
];
const array2 = [
{
dateCreated: '2021-06-02T11:14:27.348Z[UTC]',
link: 'juan ',
reason: 'lost card',
reissueRequest: {
link: 'juan ',
reason: 'lost card',
cardType: 'PHYSICAL',
personId: '2576890',
adminUser: 'juan@hotmail.com',
changePAN: true,
lastNumbers: '7231',
maintainPIN: false
},
reissuedCard: {
state: 'UNACTIVATED',
cardId: null,
cardType: 'PHYSICAL',
isPinSet: true,
lastFour: '2377',
dateCreated: '2021-06-02',
expirationDate: '2025-06-30'
}
}
];
我期待的是这样的:
const result = [
{
card: {
expiryDate: '2025-06-30',
isPinSet: true,
issuedDate: '2021-06-02',
lastNumbers: '2377',
status: 'ACTIVE',
type: 'PHYSICAL',
reissuedCard: {
state: 'UNACTIVATED',
cardId: null,
cardType: 'PHYSICAL',
isPinSet: true,
lastFour: '2377',
dateCreated: '2021-06-02',
expirationDate: '2025-06-30'
}
}
},
{
card: {
expiryDate: '2024-11-30',
isPinSet: true,
issuedDate: '2020-12-14',
lastNumbers: '7231',
status: 'TERMINATED',
type: 'PHYSICAL',
terminationDate: '2021-06-02'
}
}
];
我想先过滤,然后映射,但效果不佳。
关于如何实现这一点的任何想法?
非常感谢您的帮助!
【问题讨论】:
-
以下是否回答了您的问题?
标签: arrays filter javascript-objects intersection