I have two arrays.
allInventoryItems.length //100,000 objects
`allInventoryItems[0] // {
name: 'Something',
price: 200
}
and
currentInventory.length //~250 objects
`currentInventory[0] // {
name: 'Something Else',
price: 300
}
You get the point.
What I want to do is compare these two arrays, and if their name
property matches, update currentInventory
's price
property to the price
of the allInventoryItems
.
What is the best, and fastest way to loop through such a big array of objects, and how can I do it so that I don't have to loop 100,000 times through the allInventoryItems
?
This is my current Model:
updatePrice() {
let allInventoryItems = [];
Price.find({})
.then(items => {
allInventoryItems.push(items[0].items);
})
return new Promise((resolve, reject) => {
Inventory.find({
}).then(items => {
// Update items[0].price according to allInventory items
price
});
});
}
Update: Sorry for not being more specific.
Okay, so my Collections are like this.
Now, the Prices Collection is ALL the items, ever. And the Inventory Collection is the items that the user has in his Inventory.
The process is, that I want to update all the prices in the USER's Inventory, with the prices from the Prices Collection, where the Inventory[item].market_hash_name and the Prices[item].market_hash_name match.
Thanks!