Pardon my complete lack of javascript knowledge in advance, but I can't seem to find a good example of how to compare two arrays and create another array based the results.
I am attempting to get a list of user accounts from a storage device (uses javascript and handles MOST functions ok), and compare them against a statically created list of good users.
Using a switch statement works but I really do not like it, and I'm sure there is a much better way (userList is populated dynamically from the device when I query it):
for (userName = 0; userName < userList.length; userName++) {
switch (userList[userName]) {
case 'someuser1':
printf('Username: ' + userList[userName] + ' is goodn');
break;
case 'someuser2':
printf('Username: ' + userList[userName] + ' is goodn');
break;
case 'someuser3':
printf('Username: ' + userList[userName] + ' is goodn');
break;
default:
printf('Username: ' + userList[userName] + ' is NOT goodn');
}
}
I would like to create a third array of bad users and compare them against a new array of good users, and found users. I have started with:
var goodUsers = [someuser1, someuser2, someuser3];
However I can't figure out the right combination of multiple for loops, if statements, or otherwise to compare the two and give me an array of the bad users that I can loop through and perform actions against.
Any help would be appreciated!