Variable is undefined in JavaScript
<p>I have a method which loops through an array, but it gives me error that the variable is undefined.</p>

<pre><code>split : function(ns) {
    var splitNameSpace = ns.split('.');
    var methodName = splitNameSpace.pop();
    var context ;
    //console.log(splitNameSpace);
    for (var i=0;i&lt;splitNameSpace.length;i++){
        context =context[splitNameSpace[i]];
        console.log(context);
    }
    //console.log(context[methodName]);
    return arrayName[methodName];
}
</code></pre>
