Is this the right approach? How can we iterate through each array to compare values? Should these data structures be modified or transformed first?
Below is the data that needs to be compared. The objective is to match userID
with DocumentID
.
const videos =
[ { userID: '5lyU0TCyqRcTD3y7Rs2FGV8h2Sd2', name: 'Wedge Antilles', faction: 'Rebels' }
, { userID: '8', name: 'Ciena Ree', faction: 'Empire' }
, { userID: '40', name: 'Iden Versio', faction: 'Empire' }
, { userID: '66', name: 'Thane Kyrell', faction: 'Rebels' }
]
const blocked =
[ { id: 2, name: 'Wedge Antilles', documentID: '5lyU0TCyqRcTD3y7Rs2FGV8h2Sd2' }
, { id: 8, name: 'Ciena Ree', documentID: 'Empire' }
, { id: 40, name: 'Iden Versio', documentID: 'Empire' }
, { id: 66, name: 'Thane Kyrell', documentID: 'Rebels' }
]
var result = videos.filter(function(video) {
return blocked.some(blockedItem => video.userID === blockedItem.documentID)
})
console.log(result)