Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8091885
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:10:01+00:00 2026-06-05T20:10:01+00:00

Pardon my complete lack of javascript knowledge in advance, but I can’t seem to

  • 0

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 good\n');
            break;
    case 'someuser2':
            printf('Username: ' + userList[userName] + ' is good\n');
            break;
    case 'someuser3':
            printf('Username: ' + userList[userName] + ' is good\n');
            break;
    default:
            printf('Username: ' + userList[userName] + ' is NOT good\n');
    } 
}

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T20:10:02+00:00Added an answer on June 5, 2026 at 8:10 pm

    Array’s indexOf method is sweet. It returns the position of an element in the array, if it exists, or returns -1 if it does not.

    var goodUsers = ["someuser1", "someuser2", "someuser3"];
    var users = ["someuser1", 'basuser'];
    var user;
    
    for (var i=0; i < users.length; i++) {
      user = users[i];
      if (goodUsers.indexOf(user) >= 0) {
        console.log(user + ' is a good user');
      } else {
        console.log(user + ' is BAD!!!');
      }
    }​
    

    http://jsfiddle.net/qz5fx/1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Pardon the excessive amount of code, but I'm not sure if I can explain
Pardon for this, i just get this error in console but i can't see
Please pardon my lack of Photoshop skills, but I'm curious what type of strategy
Pardon if this question has been answered but I couldn't find it. I'm kinda
Please pardon me for being a complete newbie, but I'm following a tutorial (
Pardon me if it's simple, but what is the most efficient way to do
Pardon my ignorance, but I've never really developed Windows applications. How do you store
Pardon me if it is nave; but i am trying to set a property
Pardon the pun in my title (heh) but this is seriously driving me nuts!
Pardon my ignorance, but how would I begin to go about creating the following

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.