I have an array like this:
const data = [
{"id": 3, "value": "a"},
{"id": 3, "value": "b"},
{"id": 4, "value": "a"},
{"id": 8, "value": "d"},
{"id": 1, "value": "d"},
{"id": 2, "value": "d"},
{"id": 5, "value": "z"},
{"id": 8, "value": "h"},
{"id": 8, "value": "b"},
]
and would like to delete all objects, where the value is not the same in one of the other objects. So, at the end I would like to have:
[
{"id": 3, "value": "a"},
{"id": 4, "value": "a"},
{"id": 3, "value": "b"},
{"id": 8, "value": "b"},
{"id": 1, "value": "d"},
{"id": 2, "value": "d"},
]
I tried several versions. How to check against something which you don´t know if it is there (later in the loop)? If I do check the list against itself in a loop, I am runing in the corner, that the array itself changes its length during the for loop... Is there a simple approach?
Thanks for any help!