I have following array:
[
[val1, val2]
[val1, val2]
[val1, val2]
[valN, valN]
]
N represents the fact that these arrays are not limited, i.e I never know how much of them do I store. What I try to accomplish is converting that array to array of objects with keys lat and lng and I expect so have final result as following so I can use it for further needs:
[
{
lat: val1,
lng: val2
},
{
lat: val1,
lng: val2
},
{
lat: valN,
lng: valN
}
]
I found a function to convert these inner arrays to objects and it looks like this:
objectify(array) {
return array.reduce(function(result, currentArray) {
result[currentArray[0]] = currentArray[1];
return result;
}, {});
}
It works but output looks like this:
[
{val1: val1, val2: val2}
{val1: val1, val2: val2}
{valN: valN, valN: valN}
]
and that's not what I'm looking for, because I really need these lat and lng to be keys of an object. How can I solve such issue?