I am working with a list of user uuids stored in the myContactsUuids array. I am using the forEach() method to iterate through them and add each user, retrieved using the new ChatEngine.User(uuid) function, to the myContacts array.
myContactsUuids = ["john_doe_001", "john_doe_005"];
// initializing a global array of users
myContacts = {};
myContactsUuids.forEach(function(uuid) {
myContacts[uuid] = new ChatEngine.User(uuid);
});
Now, I want to enhance this by adding additional data nested under each uuid. I aim to pass this as a JSON object with the user uuid as a string in the ChatEngine.User() function.
Here is an example of the user data structure:
myContactsUuids = {"john_doe_001":{"username":"John Doe","avatar_url":"http://someurl"},"john_doe_003":{"username":"Another John Doe","avatar_url":"http://someurl"}};
There is also a ChatEngine.User(uuid,data) function, which takes the user uuid string and data json object. So, for each user in the loop, it would look something like this:
new $scope.ChatEngine.User("john_doe_001", {"username":"John Doe","avatar_url":"http://someurl"});
I am unsure of the best way to write a loop for this scenario and pass the necessary data to it, and then add the retrieved users to the array as in the simple function. Possibly, using each() might help, but I am not sure of the correct approach.
The solution provided by @Ele seems to work, but I require the resulting array to be formatted 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"}} }