I am going to demonstrate the essence of the question. I think this should work.
const arr = [
["apple" , 3],
["banana", 8],
["apple", 3]
];
const arr1 = ["apple", 3];
You can clearly see there is a duplicate element. But that may not be relevant at this point.
If I do the following:
isArr1Included = arr.includes(arr1);
// I expect the ouput: true
The output is false.
If I do this:
const foo = (arr[0] === arr1);
foo will be false.
So, how can I get valid results here? I come from a well rounded Python background, where I believe something like this would work properly, however I can't figure this out.
I understand that these are key-value pairs that I could use as a map instead of an array, however after some operation I will need to get back to using arrays, and I would like to avoid those extra steps of conversion.
My main goal here would be to remove the duplicate item.
Efficiency is key as these arrays can have thousands of elements(arrays)
EDIT:
Would this be faster than looping through all elements? (below)
Converting the key-value pairs within the array to strings (Array.prototype.toSting)
and finding duplicate strings with . filter
and . indexOf
or perhaps .reduce