When utilizing the code below, my goal is to filter the first array by checking if the item's id exists in the second array. However, I am encountering an issue where the result is coming back empty.
dialogRef.afterClosed().subscribe((airlines: AirlineModel[]) => {
console.log(airlines, this.airlines);
const updates = airlines.filter(airline => this.airlines.some(item => item.id === airline.id));
console.log(updates);
});
The output of
console.log(airlines, this.airlines);
shows:
(13) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: "1", code: "AAL", name: "American Airlines"}
1: {id: "6", code: "DAL", name: "Delta Airlines"}
2: {id: "526", code: "SWA", name: "Southwest Airlines"}
3: {id: "27", code: "ASA", name: "Alaska Airlines"}
4: {id: "23", code: "FDX", name: "FedEx"}
5: {id: "205", code: "NCA", name: "Nippon Cargo"}
6: {id: "406", code: "UPS", name: "United Parcel Service"}
7: {id: "160", code: "CPA", name: "Cathay Pacific"}
8: {id: "403", code: "PAC", name: "Polar Air Cargo"}
9: {id: "992", code: "GTI", name: "Atlas Air"}
10: {id: "272", code: "CKS", name: "Kalitta Air"}
11: {id: "345", code: "NAC", name: "Northern Air Cargo"}
12: {id: "615", code: "BCS", name: "European Air Transport"}
length: 13
__proto__: Array(0)
(12) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]
0: {id: 6, code: "DAL", name: "Delta Airlines"}
1: {id: 526, code: "SWA", name: "Southwest Airlines"}
2: {id: 27, code: "ASA", name: "Alaska Airlines"}
3: {id: 23, code: "FDX", name: "FedEx"}
4: {id: 205, code: "NCA", name: "Nippon Cargo"}
5: {id: 406, code: "UPS", name: "United Parcel Service"}
6: {id: 160, code: "CPA", name: "Cathay Pacific"}
7: {id: 403, code: "PAC", name: "Polar Air Cargo"}
8: {id: 992, code: "GTI", name: "Atlas Air"}
9: {id: 272, code: "CKS", name: "Kalitta Air"}
10: {id: 345, code: "NAC", name: "Northern Air Cargo"}
11: {id: 615, code: "BCS", name: "European Air Transport"}
length: 12
__proto__: Array(0)
The result of console.log(updates);
appears as:
[]length: 0__proto__: Array(0)