I have 2 arrays of objects. Each object has an Id property. Now, if I have a 3rd array of identifiers only, what is the best and fastest way to search for objects from array1 based on these identifiers and move them to array2.
Thank you very much for your reply.
Code example:
Person = function(id, fn, ln) { this.id = id, this.firstName = fn, this.lastName = ln } array1 = new Array(); // add 500 new Person objects to this array array2 = new Array(); // add some other new Person objects to this array function moveArrayItems(ids) { // ids is an array of ids eg [1,2,3,4,5,6,...] // Now I want to find all the person objects from array1 whose ids // match with the ids array passed into this method. Then move them to array2. // What is the best way to achive this? }
source share