I have the following items. I want to remove the duplicate items and return the array. I have tried using Set
but I think that is not a part of the Ecma script that I am currently using. I know this question has been asked multiples times here but I cannot seem to get mine to work.
0: (2) [0, 2]
1: (2) [0, 2]
2: (2) [1, 2]
3: (2) [1, 3]
function checkDuplicate(array: any, obj: any) {
const exists = array.some((o: any) => o.itemOne === obj.itemOne && o.itemTwo === obj.itemTwo);
if (exists) {
return true;
} else {
return false;
}
}
function check() {
const testArray: any = [];
arrayOne().map((item: any) => {
arrayTwo().map((item2: any) => {
if (item.someMatchingValue === item2.someMatchingValue) {
if (!checkDuplicate(testArray, [item.itemOne, item2.itemTwo])) {
testArray.push([item.itemOne, item2.itemTwo]);
}
}
});
});
console.log(testArray);
return testArray;
}