I have a TypeScript plain old JavaScript object (POJO) structured as shown below:
export interface Items {
firstName?: String;
lastName?: String;
address?: String;
phoneNumber?: number;
city?: String;
state?: String;
zipcode?: number;
accountId?: number;
status?: String;
approvalStatus?: String;
txId?: number;
rxId?: number;
txBankName?: String;
rxBankName?: String;
txCcy?: String;
rxCcy?: String;
txCcyAmt?: number;
rxCcyAmt?: number;
txDate?: date;
rxDate?: date;
}
In my HTML file, I have a form that includes all the fields from the above POJO. When a user selects a field, the POJO is updated with the entered text.
However, users have the option to leave many fields empty, resulting in corresponding properties in the object being set to null.
Upon clicking the submit button, when I examine the POJO, it appears as shown in the screenshot below:
https://i.sstatic.net/N8lTI.jpg
I want to create another array that only contains the populated values (excluding the null properties).
this.anotherArray = [ {name: firstName, value: "Andy"}, {name: lastName, value: "Smith"}]
I intend to utilize this array for an ngFor list to display Angular Material chips.
How can I achieve this in a highly optimized manner?
edit: My question pertains to checking null properties in an object, whereas the referenced duplicate question relates to an array. The solutions presented also differ, with my approach involving the use of Object.entries, as opposed to the duplicate reference which utilizes map and Object.keys.