I have a variable of the form:
var data=[
{
start:22,
end: 8
},
{
start:60,
end: 43
},
{
start: 35,
end: 55
},
{
start:25,
end:40
}
];
I want to map it to look like this
var newData = { 22:8, 60:43, 35:55, 25:40};
Is this possible? I mainly just want to use the start numbers as a key to access the end numbers without using search. I have tried to do this:
var mapData = data.map(function(data){
var x = {};
x[data.start]=data.end;
return x;
});
but it gives: 0 : {22: 8} 1 : {60: 43} 2 : {35: 55} 3 : {25: 40} which means i have to use 0, 1,2, 3 as indices.
newDatais not a valid object.{ 22:8, 60:43, 35:55, 25:40 }?