Below are my two arrays.
let clientCollection = ["1","ABC","X12","OE2","PQ$"];
let serverCollection = [{
"Id": "1",
"Name": "Ram",
"Other": "Other properties"
},
{
"Id": "ABC",
"Name": "Shyam",
"Other": "Other properties"
},
{
"Id": "OE2",
"Name": "Mohan",
"Other": "Other properties"
}]
Now I need to compare the two collections above and create two for the arrays
let matchedIds = [];
let unMatchedIds = [];
Now this is what I am doing now.
for(let i =0 ; i < clientsCollection.length;i++)
{
if(_.indexOf(serverCollection, clientCollection[i]) >= 0)
{
matchedIds.push(clientCollection[i]);
}
else
{
unMatchedIds.push(clientCollection[i]);
}
}
In my application, the size of these arrays can increase to 1000 or more. This can have effective problems.
I use underscore and try if I can get a better solution but can't find.
Can someone please suggest if I can do the same thing more efficiently using underscore + ES6 ??
source
share