Is there a way to transform this: [[a1, b1], [a2, b2]]
into this format?
[{x1: a1, y2: b1}, {x2: a2, y2: b2}]
?
Please note that the properties x1
and x2
are newly introduced with values a1
, b1
, etc.
I attempted to achieve this with the following code snippet:
formatData.map((data, index) => {
const obj = {
dataX: data[index][0],
dataY: data[index][2]
}
data = obj
}
However, I encountered a roadblock in the process.