Within my class, I defined an array:
myUsers = new Array();
I am looking to add usernames to this array in a unique manner. My approach involves checking if the array length is 0 and if so, adding a user. This method works well for adding the first user. However, when attempting to add another user that already exists in the array, it should replace the existing one. Strange behavior occurs as follows: - When I add the first user, the console shows: ["User1"] - Upon trying to add another user (User2), the console displays: ["User1", empty] I am unable to determine what is causing this issue...
isChecked(e) {
var usersArray = this.myUsers;
console.log(usersArray.length);
if(this.myUsers.length == 0) {
console.log("is 0");
this.myUsers.push(e);
} else {
console.log("is not 0");
for (var i= 0; i < this.myUsers.length; i++) {
if (this.myUsers[i] == e) {
console.log("is in array");
delete this.myUsers[i];
} else {
this.myUsers.push(e);
}
}
}
}