Below is the current data
const data = [
{ id: 1, type: "call", strike: 3000, volume: 50000 },
{ id: 2, type: "call", strike: 5000, volume: 30000 },
{ id: 3, type: "call", strike: 7000, volume: 20000 },
{ id: 4, type: "put", strike: 3000, volume: 50000 },
{ id: 5, type: "put", strike: 5000, volume: 10000 },
{ id: 6, type: "put", strike: 7000, volume: 7000 }
]
I want to do some processing of the data
based on strike
, which means the object with same value in strike
will be combined, so that it becomes something like
[{strike: 3000, callVolume: 50000, putVolume: 50000 },{strike: 5000, callVolume: 30000, putVolume: 10000 }, {strike: 5000, callVolume: 20000, putVolume: 7000 }]
How should I do it in javascript?