Assume...
let A = [{ x:'x', y:'y' }, { x:'x', y:'y' }];
I know I can transform this array into a new one taking and renaming the y
property like this...
A.map(o => ({ v: o.y }));
// [{ v:'y' }, { v:'y' }]
And I can use a spread to get all existing properties plus a new, transformed one like this...
A.map(o => ({ ...o, ...{ v: o.y } }));
// [{ x:'x', y:'y', v:'y' }, { x:'x', y:'y', v:'y' }]
But I'm wondering if there's an elegant way to simply rename the y
property to v
. So here's what I want.
// [{ x:'x', v:'y' }, { x:'x', v:'y' }]
I know I can use a function block on my fat arrow function, add a v
property, and delete the y
property, but that's cumbersome. I'm looking for something elegant.