I have an array of strings, each containing comma separated values.
I'd like to transform this into an array of objects.
For example, I have:
var myarray = [
"a1,b1,c1,d1",
"a2,b2,c2,d2",
"a3,b3,c3,d3"
]
... which should end up as:
[
{
"field1": "a1",
"field2": "b1",
"field3": "c1",
"field3": "d1"
},
{
"field1": "a2",
"field2": "b2",
"field3": "c2",
"field2": "d2"
},
{
"field1": "a3",
"field2": "b3",
"field3": "c3",
"field3": "d3"
},
]
I've tried various approaches, like Object.assign and the spread operator. But it seems like there must be a simpler way to do this using destructuring or another approach.