I have an array of JS objects:
var a = [{a:"a1",b:"b",c:"c",prop:false},
{a:"a1",b:"b",c:"c",prop:false},
{a:"a",b:"b",c:"c",prop:false},
{a:"a2",b:"b",c:"c",prop:false},
{a:"a3",b:"b",c:"c",prop:false},
{a:"a1",b:"b",c:"c",prop:false}];
I should find duplicates of the last element, but NOT looking at the key prop: when I find them, the prop boolean associated with it should be set to true.
I did the simplest thing in the world and it works great, but I wandered if there is something that JS can do (without third-party libraries), better either in "elegance", news, or performance:
var toTest = a[a.length-1];
for(var i=0;i<a.length;i++){
if(toTest.a==a[i].a && toTest.b==a[i].b && toTest.c==a[i].c){
a[i].prop = true;
a[a.length-1].prop = true;
}
}
Any advice is welcome.
user1094081
source
share