I have the following array of mergeUniqueItems:
var mergeUniqueItems = ["-JsDEcxz_ZSGFLKwd1QM",
"-JsJ2NXGDYKI6QRsuXVK",
"-JsJ2RK-kOG2eGcG04xF",
"-JsJ2RK-kOG2eGcG04xF",
"-JsJ2YLPiP6751zh8geS"]
After using this code snippet, I encountered an issue:
var duplicateArray = [];
for (var i = 0; i < mergeUniqueItems.length; i ++){
for (var j = 1; j < mergeUniqueItems.length; j ++){
if (mergeUniqueItems[i] == mergeUniqueItems[j]){
duplicateArray.push(mergeUniqueItems[i]);
}
}
}
console.log(duplicateArray);
The resulting duplicateArray contains the following items:
["-JsJ2NXGDYKI6QRsuXVK",
"-JsJ2RK-kOG2eGcG04xF",
"-JsJ2RK-kOG2eGcG04xF",
"-JsJ2RK-kOG2eGcG04xF",
"-JsJ2RK-kOG2eGcG04xF",
"-JsJ2YLPiP6751zh8geS"]
However, my expectation is to have only one array entry for each duplicated item like below:
["-JsJ2RK-kOG2eGcG04xF"]
If there are multiple duplicate values, the array should display them as follows:
["-JsJ2RK-kOG2eGcG04xF", "another_duplicate_1", "another_duplicate_2", ...]
I am unable to determine what's causing this issue with my code. Your assistance would be greatly appreciated.
Thank you