This question might be a simple iteration, but I'm stuck in the logic.
I have an array of data which needs to be iterated based on id and code and remove the data only when the code is not present in the given id's.
Here is the Case Scenarios, From the below data,
- There are two different code named "GOOGLE" with different id - Valid Case
- There are two different code named "FACEBOOK" with different id - Valid Case
- There is a code named "TWITTER" which is not present in another id - INVALID Case.
Here, I wanted to remove this data based on case 3.
{
"id" : 378,
"code" : "TWITTER",
"comment" : "zeeer"
}
Can someone help me with this scenario?
****Below is the original array data****
data = [ {
"id" : 381,
"code" : "GOOGLE",
"comment" : "ffff"
}, {
"id" : 381,
"code" : "FACEBOOK",
"comment" : "fff"
}, {
"id" : 378,
"code" : "TWITTER",
"comment" : "zeeer"
}, {
"id" : 378,
"code" : "GOOGLE",
"comment" : "rferer"
}, {
"id" : 378,
"code" : "FACEBOOK",
"comment" : "fefehh"
} ]
I tried something below, but not sure how to proceed after this.
And, I'm using angular 7 and it will be helpful if I get the solution based on typescript.
this.data.forEach((row, index) => {
let value = row.id;
if(originalArray.indexOf(value) == -1) {
console.log(value);
}
originalArray.push(row);
})