I need to convert an array of strings, each with comma separated values, into an array of objects.
Here is an example:
var myarray = [
"a1,b1,c1,d1",
"a2,b2,c2,d2",
"a3,b3,c3,d3"
]
This should be transformed into:
[
{
"field1": "a1",
"field2": "b1",
"field3": "c1",
"field4": "d1"
},
{
"field1": "a2",
"field2": "b2",
"field3": "c2",
"field4": "d2"
},
{
"field1": "a3",
"field2": "b3",
"field3": "c3",
"field4": "d3"
}
]
I have experimented with different methods like using Object.assign and the spread operator. However, I believe there might be a more straightforward solution involving destructuring or another technique.