can't get object from custom javascript object array property using object method
<p>I have a javascript class with an array property.  I'm created a method on the object to return a specific object from that array.  However it's not working as I expected.  I don't get an error in any browser but when I try to put it into jsfiddle I get back an error saying </p>

<p>Error:
Problem at line 5 character 18: Cannot set property 'first' of undefined
Implied global: Page 1</p>

<p>I have no idea what that means but it's referring to this line</p>

<pre><code>for (var i = 0; i &lt; obj.containerDivs.length; i++) {
</code></pre>

<p>Here's the full code.  Can anyone tell me what I'm doing wrong?  Why won't the GetContainerDiv function return the dv but later when I iterate through the elements without the function it works fine.  Thanks.</p>

<pre><code>Page = function() {
    this.containerDivs = ["div1", "div2", "div3"];

    this.GetContainerDiv = function(obj, divId) {
        for (var i = 0; i &lt; obj.containerDivs.length; i++) {
            if (obj.containerDivs[i] == divId) return d;
        }
        return null;
    }
}

var page = new Page();

var dv = page.GetContainerDiv(page, "div1");
console.log(dv);

for (var i = 0; i &lt; page.containerDivs.length; i++) {
    if (page.containerDivs[i] == "div1") console.log(page.containerDivs[i]);
}
</code></pre>
