0

Having some minor problems with a loop I'm doing. It doesn't seem to be running, even though all the conditions should be met...

Code:

for (var i = 0; i > obj.length; i++) {
    console.log(i);

    if (obj[i]["val3"] === true) {
         objReturned = obj[i]["val2"];
    }
}

console.log(objReturned);

Simple enough right? Here's how the object roughly looks, I've tried debugging by logging contents of the JSON obj, and I am successfully in retrieving any value using the object notation (eg. obj[0].Active).

It's just NOT working in my loop? Am I forgetting something here?

[
    {
        "val1": "organisationname1",
        "val2": 1,
        "val3": true
    },
    {
        "val1": "organisationname2",
        "val2": 2,
        "val3": false
    },
    {
        "val1": "organisationname3",
        "val2": 3,
        "val3": false
    }
]
0

1 Answer 1

6

Typo:

for (var i = 0; i > obj.length; i++) {

Should be:

for (var i = 0; i < obj.length; i++) {
              //  ^ There.
Sign up to request clarification or add additional context in comments.

4 Comments

Well, you're just magnificent. I'm an idiot, thank you so much :D
@NichlasTorgersen: No problem ;-) Typo's happen. If a loop's not looping, the loop condition should always be the first thing you check. Then again, I've overlooked stuff like this way too often :P Any way, please consider marking this as the answer, when the cooldown expires.
I have clicked it frantically for the last 15 minutes. I kinda know, I guess I've been sitting still for too long, usually syntax isn't a problem...
Sorry, fixed! Can't always be available everywhere.

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.