I am initializing an empty array in the nowjs.on('newgroup') event, so that each group created gets an empty userList array.
Immediately after I initialize it, I console.log it, and it is not an Array, but an Object.
I am unable to use it like an array, it makes entries like {'0': { memberName: 'test'}} instead of an array like [{memberName: 'test'}].
nowjs.on('newgroup', function (group) {
console.log('Nowjs group created: ' + group.groupName);
group.now.userList = [];
// i have also tried group.now.userList = new Array() here, same issue
console.log('userList=' + Util.inspectObject(group.now.userList));
// this prints userList={} (brackets, not braces)
group.on('leave', function () {
console.log('userList=' + Util.inspectObject(group.now.userList));
var currentClientId = this.user.clientId;
removeClient(group, currentClientId);
// this tries to do group.now.userList.splice to take a member out of the array, but it can't use group.now.userList like an array
group.now.eventServerToClient('group.removeMember', null, currentClientId);
});
group.on('join', function () {
console.log('userList=' + Util.inspectObject(group.now.userList));
var currentClientId = this.user.clientId;
var newUser = addClient(group, currentClientId, this.now.memberName);
// this tries to do group.now.userList.push to add a member to the array, but it can't use group.now.userList like an array
group.now.eventServerToClient('group.addMember', newUser, currentClientId);
});
});