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.
rv
being empty, unlessdbInfo.emails
is empty. I just tested it.id
,firstname
andlastname
properties are fine, but you should have anemail
property that is an array, containing the multiple email addresses.