I have two CSV files:
balldata.json
[
{
\"id\": \"1\",
\"color\": \"red\",
},
You can do it like below
const result = [courtdata, balldata].reduce((p, q) => p.map((c, i) => Object.assign({}, c, {color: q[i].color})));
// Result
[
{court_id: 2001, ball_in_use: "1", color: "red"},
{court_id: 2005, ball_in_use: "2", color: "blue"}
]
else use below
const result = [courtdata, balldata].reduce((p, q) => p.map((c, i) => Object.assign({}, {[c.court_id] : q[i].color})))
//Result
[
{2001: "red"},
{2005: "blue"}
]
Working example https://codesandbox.io/s/react-example-b7bfm