I am looking to filter out certain elements from an array in TypeScript
Original Array:
[
{"Id":"3","DisplayName":"Fax"},
{"Id":"1","DisplayName":"Home"},
{"Id":"4","DisplayName":"Mobile"},
{"Id":"2","DisplayName":"Office"},
{"Id":"5","DisplayName":"Other"}
]
Selected Array:
[
{"PhoneNumberId":127436,"ContactId":22222,"IsPrimary":true, "PhoneType": {"Id":"2","DisplayName":"Office"},"PhoneNumber":"111111111","Extension":"","DisplayPhoneNumber":"111-111-1111"},
{"PhoneNumberId":127437,"ContactId":22222,"IsPrimary":false,"PhoneType":{"Id":"3","DisplayName":"Fax"},"PhoneNumber":"111111111","Extension":null,"DisplayPhoneNumber":"111-111-1111"},
{"PhoneNumberId":173825,"ContactId":22222,"IsPrimary":false,"PhoneType":{"Id":"4","DisplayName":"Mobile"},"PhoneNumber":"111111111","Extension":"","DisplayPhoneNumber":"111-111-1111"}
]
To get the desired result, I attempted this filter method but it did not work as expected.
this.filteredArray = this.originalArray.filter(item => !this.selectedArray.some(itemToRemove => itemToRemove['Id'] == item['Id']));
The end goal is to have the original array filtered to display only specific items:
Filtered Array:
[
{"Id":"1","DisplayName":"Home"},
{"Id":"5","DisplayName":"Other"}
]