This is my array:
array = [
{ animal: 'dog', leg: 4, age: 3 },
{ animal: 'chicken', leg: 2, age: 2 },
{ animal: 'egg'},
];
This is my desired array:
desiredArray = [
{ animal: 'dog', leg: 4, age: 3, sum: 7 },
{ animal: 'chicken', leg: 2, age: 2, sum: 4 },
{ animal: 'egg', sum: 0 },
];
I want to add a property to each object in the array which is the sum of the leg and the age. If leg or age is null, it will have a value of 0.