Is there a way to remove or filter out subsequent arrays and their values if a duplicate id
is found in the previous array? For instance:
const a1 = ["id1", "b", "c", "d", "e"],
a2 = ["id2", "y", "z", "w", "v"],
a3 = ["id3", "k", "j", "i", "f"],
a4 = ["m", "n", "o", "p", "id2"],
a5 = [1, 2, "id1", 3, 4]
If an id1
is present in a5
and id2
in a4
, the arrays containing these duplicate id
should be removed or filtered out, keeping only the first occurrence of each unique id
. Therefore, the expected output for the above example would be:
[
["id1", "b", "c", "d", "e"],
["id2", "y", "z", "w", "v"],
["id3", "k", "j", "i", "f"]
]