I got an array person containing many objects that look like this:
const person = [
{ first: 'firstName', last: 'lastName', year: 1439, passed: 1495 },
...
]
I have counted how many years the person lived:
const oldest = person.map(x => x.passed - x.year);
Got new array with the years for every person.
Now I would like to push this calculated year as a new property age to each person object in this array.
Can you help me out?
You could add a new property
person.forEach(p => p.lifetime = p.passed - p.year);
Or map a new array of objects
persons = person.map(p => ({ ...p, lifetime: p.passed - p.year });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With