NoOne
NoOne

Reputation: 104

object with array type string causing a typeError

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?

Upvotes: 0

Views: 122

Answers (1)

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

Upvotes: 2

Related Questions