6
rated 0 times
[
7]
[
1]
/ answers: 1 / hits: 26587
/ 10 Years ago, mon, december 29, 2014, 12:00:00
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: [email protected]
1: [email protected]
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: [email protected]
}
1:
{
name: [email protected]
}
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.
More From » arrays