Help! For Loops through multiple arrays

I am so lost. I think I should be using for loops to pull back the data but unsure of really where to start.

Basically, I want conditional logic to run against 3 arrays. That logic is: if var web ==“Y” && var audit == “AP.PEND” bring back var user else if var web==“N” && var audit== “INITCOMP” bring back var user. All 3 variables are arrays.

I think I have all the pieces but just not sure how to put them all together.

Any help would be appreciated!

var web = array 1;
var audit = array 2;
var user = array 3;

if (web =="Y"  && audit == "AP.PEND")
{ user;
{ if (web=="N"  && audit== "INITCOMP")
{ user;

for (i=0; i < web.length; i++) {

for (i=0; i < audit.length; i++) {


for (i=0; i < user.length; i++) {


Thanks for the quick response!

Bring back = Return the value.

Not sure how to show you the arrays. I am pulling from tables that I cannot “see” which is why I think I am struggling so much. I understand how to do the if/else for loops when I can see or know the data in the array but in this instance the only thing I know is to look for the value provided in array 1 and array 2. Then if that matches return the value in array 3 that would correlate.

I have attached a screenshot of the data that I can see. It is sample data. I did have to black out some of it.

Here is mock code of what i could comprehend from your explanation, could be close to what your intent is

const arrOne = ['y', 'y', 'n']
const arrTwo = ['one', 'two', 'three']
const arrThree = ['purple', 'pink', 'white']

for (const i in arrOne) {
  if (arrOne[i] === 'y' && arrTwo[i] === 'one') {
    // or console.log(arrThree[i]) ??
    return arrThree[i]

  if (arrOne[i] === 'n' && arrTwo[i] === 'two') {
    // or console.log(arrThree[i]) ??
    return arrThree[i]

Keep in mind to use return, you need to have the code wrapped in a function and once you call return the function will stop executing.

Thank you so much!! I will try it.

if I may give some advice that you did not ask for…

If you use the code above, you will halt your learning.
That is of course up to you, but if you hope to learn enough JS, you may want to ignore the previous post until you are done with this exercise yourself.

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.