1

What I mean by "can't access" is that the loop doesn't initiate. Sorry for the confusion.

I asked this question before, but I'm trying again with more detail and the complete-ish code.

Basically, I'm filtering output based on a user's input. However, I'm confused as to why I have no access to the obj["Entry Fee"] value and the toFilterParams.entry array inside the for loop that I have marked in the code above. I have access to it just before that loop starts, but nothing ever triggers inside the loop (yes, the array is visible before the for loop I marked and all the criteria is filled before the code starts).

I tried setting the object's value in a variable just before the loop starts, but obviously that didn't do anything.

For reference, toFilterParams is set up like {games: [], entry: [], dates: []};

Here is the code with the labeling of where I can access the array and the object value and where I cant:

db = _.without(_.map(dbTransition, function(obj){

    if("Starting_Date" in obj){

        if(toFilterParams.games.length > 0){

            // repeat of code I have below

        } else if(toFilterParams.games.length === 0){

            // Have access to obj["Entry Fee"] and toFilterParams.entry array**
            if(toFilterParams.entry.length > 0){

                // Have access to obj["Entry Fee"] and toFilterParams.entry array**

                for(var x = 0, xx = toFilterParams.entry; x < xx; x++){

                    // Have no access to obj["Entry Fee"] and toFilterParams.entry array aka the loop here doesn't initiate.**

                    if(Number(toFilterParams.entry[x]) !== Number(obj["Entry Fee"])){

                        if(toFilterParams.dates.length > 0){

                            var startDate = Date.parse(toFilterParams.dates[0]);
                            var endDate = Date.parse(toFilterParams.dates[1]);
                            var FinalDate = Date.parse(obj["Starting_Date"]);

                            if(FinalDate >= startDate && FinalDate <= endDate){
                                return obj;
                            }

                        } else{
                            return obj;
                        }
                    }
                }
            } else if(toFilterParams.entry.length === 0){

                if(toFilterParams.dates.length > 0){

                    var startDate = Date.parse(toFilterParams.dates[0]);
                    var endDate = Date.parse(toFilterParams.dates[1]);
                    var FinalDate = Date.parse(obj["Starting_Date"]);

                    if(FinalDate >= startDate && FinalDate <= endDate){
                        return obj;
                    }
                } else{
                    return obj;
                }
            }
        }

    }

}), undefined);

So basically, I have no idea what is going on and would like any help to solve this. Thanks.

6
  • Could you describe what you have done for debugging? Can you use the Chrome debugger / Firebug to look at this? Commented Feb 23, 2016 at 21:51
  • Can you make a MCVE that includes values of all the relevant variables? Commented Feb 23, 2016 at 21:51
  • Please define "access", an error occurs? How have you determined, that you don't have "access". Commented Feb 23, 2016 at 21:55
  • Not having access = the loop doesn't initiate = console.log doesn't fire inside the loop. I should have made that clearer. Commented Feb 23, 2016 at 21:58
  • @Julie I'm doing this on the Meteor framework, so all spelling issues and errors in the code are presented to me via terminal, so I always see it before the code can save and render. Commented Feb 23, 2016 at 22:00

1 Answer 1

2

The for loop is never executed. This happens, because toFilterParams.entry is an array. In the condition of for loop you're checking against array. To fix this, you need to set the length of the array to xx not the array itself:

for(var x = 0, xx = toFilterParams.entry.length; x < xx; x++){...
Sign up to request clarification or add additional context in comments.

1 Comment

Completely forgot about that fact. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.