{
const array1 = [{
val1: 0,
val2: 0,
val3: 0,
year: "2018"
}, {
val1: 1,
val2: 1,
val3: 1,
year: "2019"
}];
const array2 = array1.reduce((m, v)=>{
const { map, result } = m;
const { year } = v;
for(const key of Object.keys(v)) {
if(key === "year")
continue;
if(key in map === false)
result.push(map[key] = {
Name: key
});
map[key][year] = v[key];
}
return m;
}, { map: {}, result: [] }).result;
console.log(array2);
}