JSFiddle - React, Tailwind, and code Playground
by Eugen Sunic
JavaScript
var ranking = [{
def: "0.58",
league: "Scottish Premiership",
name: "Celtic",
off: "3.33",
grank: "3",
tform: "96.33",
},
{
def: "2.52",
league: "Scottish Premiership",
name: "Dundee",
off: "1.28",
grank: "302",
tform: "27.51",
}
]
var matches = [{
date: "2010-04-22",
league: "Scottish Premiership",
home: "0.0676",
away: "0.8",
draw: "0.1324",
goals1: "3",
goals2: "1",
tform1: "96.33",
tform2: "27.51",
team1: "Celtic",
team2: "Dundee",
}]
function extractUniqueProps(arr) {
return arr.reduce((acc, x, i) => {
keys = Object.keys(x);
keyValue = keys.map((y, j) => ({
[y + i]: x[y]
})).reduce((acc2, y) => ({
...acc2,
...y
}), {})
acc = {
...acc,
...keyValue
}
return acc;
}, {}
)
}
const result= {...extractUniqueProps(ranking),...extractUniqueProps(matches)}
console.log(result)