Skip to content Skip to sidebar Skip to footer

Javascript Object Property Not In Scope

I seem to have a problem with objects' properties' scope. I would like to output each of the Message objects' title and message properties to a select element, but it is Not Workin

Solution 1:

don't use for (c in messages).

in is for iterating over properties of an object, not for iterating over values in an array.

Use the tried and true

for(var i = 0; i < messages.length; i++) {
...
}

Also, you are not putting your getTitle and getMessage methods on a prototype, which is kind of wasteful.

Solution 2:

the syntax for the for in loop in js is :

for(var key in obj)
    {
        var currentElement = obj[key];
    }

Post a Comment for "Javascript Object Property Not In Scope"