I need convert arrays inside my parent array to objects to match my database model data.
I have array like this:
emails: Array[2]
0: "example@mail.com"
1: "otherexample@mail.com"
id: 1
firstname: "Jane"
lastname: "Doe
What I want to achieve is to convert emails array to array of objects like this:
emails: Array[2]
0:
{
name: "example@mail.com"
}
1:
{
name: "otherexample@mail.com"
}
id: 1
firstname: "Jane"
lastname: "Doe
I tried to use this code to convert array to object but for some reason it fails (no data are displayed -> variable rv is empty):
var rv = {};
for (var i = 0; i < dbInfo.emails.length; ++i)
if (dbInfo.emails[i] !== undefined) rv[i] = dbInfo.emails[i];
Does someone knows why my code fails and does someone knows solution for this type of problem?
Thanks advance.