I have this array:
[
{
"name": "Homer Simpson",
"age": "43",
"start_time": null,
"end_time": null
},
{
"name": "Bart Simpson",
"age": "14",
"start_time": "2023-11-10T20:08:10Z",
"end_time": "2023-11-10T20:08:10Z"
}
];
How do I omit the start_time and end_time from each object if the value is NULL? I would like to end with this array:
[
{
"name": "Homer Simpson",
"age": "43"
},
{
"name": "Bart Simpson",
"age": "14",
"start_time": "2023-11-10T20:08:10Z",
"end_time": "2023-11-10T20:08:10Z"
}
];
I know I can loop through each object and push into a new array with the omitted values if the time values are null, but is there a more concise way of doing it? Is there a way I can use Array.filter?