I have the following string:
area = "73,159,160,178,165,340,70,382"
;
And I need to convert it to the following format:
area = [
{
"x": 73,
"y": 159,
},
{
"x": 160,
"y": 178,
},
{
"x": 165,
"y": 340,
},
{
"x": 70,
"y": 382,
}
]
I can start by converting it to a normal array:
JSON.parse("[" + area + "]")
But I'm now stuck on how to make the nested objects. How would I now know what is every other odd and even number and allocate it to the corresponding object?