I have an object, which has 2 objects whithin and some properties of interest.
myObject = {
"chart":{
"data":[
{
"name":"First",
"x":[
"2000-01-01T00:00:00",
"2000-02-01T00:00:00",
"2000-03-01T00:00:00",
],
"y":[
1,
2,
3,
],
"type":"scatter"
},
{
"name":"Second",
"x":[
"2000-01-01T00:00:00",
"2000-02-01T00:00:00",
"2000-03-01T00:00:00",
],
"y":[
1,
2,
3,
],
"type":"scatter"
},
],
"otherKey":{
"whatever":"line"
}
},
};
I'm trying to create a new "object" which is an array
of objects, and the only keys of interest are name
and point
, with point being an array of x
and y
combined.
newObject = [
{
"name":"First",
"point":[
["2000-01-01T00:00:00", 1],
["2000-02-01T00:00:00", 2],
["2000-03-01T00:00:00", 3],
],
},
{
"name":"Second",
"point":[
["2000-01-01T00:00:00", 1],
["2000-02-01T00:00:00", 2],
["2000-03-01T00:00:00", 3],
],
},
];
I'm trying to use map
and filter
function but I'm getting lost somewhere in the middle.
newObject = myObject.chart.data.map((value) => {
return [
value.x,
value.y
]
});
I think I need to concatenate them properly. I'm a JS begginer, any tip or guidance would help, thanks.