I need to convert arrays inside my parent array to objects according to the data in my database model.
I have an 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 an array of email addresses to an array of such objects:
emails: Array[2]
0:
{
name: "example@mail.com"
}
1:
{
name: "otherexample@mail.com"
}
id: 1
firstname: "Jane"
lastname: "Doe
I tried using this code to convert an array to an object, but for some reason it fails (data is not displayed -> rv variable is empty):
var rv = {};
for (var i = 0; i < dbInfo.emails.length; ++i)
if (dbInfo.emails[i] !== undefined) rv[i] = dbInfo.emails[i];
Does anyone know why my code crashes, and does anyone know a solution to this type of problem?
Thanks in advance.
source
share