0

The best way to explain this is just to show you.

var condition = 70;
var formnames = new Array("wheelcheckbox1", "wheelcheckbox2","spokecheckbox","spokecheckbox2","tirecheckbox","tirecheckbox2","tirecheckbox3");

formnames.forEach(function(entry) {
   console.log(obj.entry);
   if(obj.entry == "") {
       condition = condition - 10;
   }
});

as you can see I used the console log to show how it needs to work as that works perfect, however, using the array causes an error as they're strings and not what the obj wants, it wants text without it being a string.

Any ideas?

2
  • Code should be posted here; the site has ample provisions for it. Commented Apr 24, 2016 at 22:42
  • 2
    Should be obj[entry] not obj.entry. Commented Apr 24, 2016 at 22:54

1 Answer 1

2

for..in should not be used to iterate over an array. Consider using forEach instead.

Sign up to request clarification or add additional context in comments.

4 Comments

What does the error message said? Could You fix it?
well with the obj.entry it comes out as undefined
well obj.any of the things in the array works great for instance, obj.wheelcheckbox1 works perfect, just well i use an array of strings it doesn't work at all
Oh, there's obj somewhere outside of the posted code. Then Pointy's comment above is correct.

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.