I have the below array
const dummyData =[
{
"plateID":"1234567",
"freezer":"fridzer A",
"shelf":"1",
"box":"1",
"position":"1",
},
{
"plateID":"1234567",
"freezer":"fridzer B",
"shelf":"1",
"box":"1",
"position":"1",
},
{
"plateID":"1234567",
"freezer":"fridzer C",
"shelf":"12",
"box":"11",
"position":"13",
},
{
"plateID":"1234567",
"freezer":"fridzer A",
"shelf":"1",
"box":"1",
"position":"1",
},
{
"plateID":"1234567",
"freezer":"fridzer A",
"shelf":"5",
"box":"2",
"position":"3",
},
{
"plateID":"1234567",
"freezer":"fridzer C",
"shelf":"12",
"box":"11",
"position":"13",
},
]
I want to match "freezer","shelf","box","position" value and find the index of duplicate value.
The output will be like
[
0,
2,
3,
5
]
I have tried the below approach but only able to match one column at a time (Not all columns)
let duplicates = [];
let tempArray = {};
dummyData.forEach((item, index) => {
tempArray[item.freezer] = tempArray[item.freezer] || [];
tempArray[item.freezer].push(index);
});
for (var key in tempArray) {
if (tempArray[key].length > 1) {
duplicates = duplicates.concat(tempArray[key]);
}
console.log(duplicates);
console.log(tempArray);
}
Is there ay way to match all four columns at a time and find the index of duplicate value ?