How to check for a JavaScript Object given it's name as a string?
<p>I'm having trouble figuring out how I can take a string of an object name and check if that object actually exists.</p>

<p>What I'm trying to accomplish is have an array the defines the required objects for a particular JavaScript "module" to work, for instance:</p>

<pre><code>var requiredImports = ['MyApp.Object1', 'MyApp.Object2'];
</code></pre>

<p>Then using <code>requiredImports</code>, I want to loop over them and check if the are defined. Without using the above array, I can do the following which is what I'm trying to accomplish:</p>

<pre><code>if (MyApp.Object1 == undefined) {
    alert('Missing MyApp.Object1');
}
</code></pre>

<p>But using the above, I'd have to hard code this for every module rather than making a generic method that I can just pass it an array of strings and have it effectively do the same check for me.</p>

<p>I tried doing this by just passing it the objects themselves such as:</p>

<pre><code>var requiredImports = [MyApp.Object1, MyApp.Object2];
</code></pre>

<p>But that throws a JavaScript error when those objects do not exist, which is what I'm trying to catch.</p>
