The title is very wordy, so I will demonstrate the idea with an example and a working code:
Consider a large song library available in a store. Lets call it "bigarray". A client has his/her own personal library of purchased songs from that store: "smallArray". BigArray elements has a property "purchased". I need to set that property to "true" if there is a match by id between songs of both arrays. A working code example:
for (let i = 0; i < bigArray.length; i++) {
for (let j = 0; j < smallArray.length; j++) {
if (bigArray[i].id === smallArray[j].id) {
bigArray[i].purchased = true;
}
}
}
Is there a way to program that using array methods like map, filter etc. with predicate functions possibly in one line, instead of a double for loop?