I have a list of user uuids in myContactsUuids array, using forEach() method to loop through them and add user which is retrieved with new ChatEngine.User(uuid) function to myContacts array.
myContactsUuids = ["john_doe_001", "john_doe_005"];
// set a global array of users
myContacts = {};
myContactsUuids.forEach(function(uuid) {
myContacts[uuid] = new ChatEngine.User(uuid);
});
Now trying to rewrite this to do essentially the same, but have additional data nested under each uuid and pass that as JSON object with user uuid as string in ChatEngine.User() function.
I have user data now like this, though can format in in any way.
myContactsUuids = {"john_doe_001":{"username":"John Doe","avatar_url":"http://someurl"},"john_doe_003":{"username":"Another John Doe","avatar_url":"http://someurl"}};
and ChatEngine.User(uuid,data) function where uuid is user uuid string and data json object so for e.g. user in loop look like this :
new $scope.ChatEngine.User("john_doe_001", {"username":"John Doe","avatar_url":"http://someurl"});
Just not sure what would be the best way to write loop for this and pass needed data to it, and then add retrieved user to array like did in simplified function. Perhaps I could do that using each(), but not sure how to correctly.
@Ele solution works, just need result array to be in format like this:
{ "john_doe_001":{"uuid":"john_doe_001","data":{"username":"John Doe","avatar_url":"http://someurl"}},"john_doe_003":{"uuid":"john_doe_003","data":{"username":"Another John Doe","avatar_url":"http://someurl"}} }