Let's say that I have an array of objects like this:
var messages = [
{id: 1, replyTo: null}
{id: 5, replyTo: null}
{id: 7, replyTo: null}
{id: 9, replyTo: 7}
{id: 10, replyTo: null}
{id: 12, replyTo: 1}
{id: 16, replyTo: 1}
{id: 20, replyTo: 1}
{id: 24, replyTo: 1}
{id: 28, replyTo: 1}
{id: 32, replyTo: 1}
{id: 36, replyTo: 1}
{id: 40, replyTo: 1}
];
And that I want to remove all objects from that array that has a property id of 1, but also a replyTo of 1.
I tried something like this:
for (var i = 0; i < messages.length; i++) {
if (messages[i].id === 1 || messages[i].replyTo === 1) {
messages.splice(i, 1);
}
}
And this did not work.
How can I solve this problem?