Check if [i] exists or not
<p>I am trying to run a script where i want part to run if [i] exists (meaning that there is a value of [i], any value) or another part to run if there is no value for [i], can anyone enlight me?</p>

<p>I am talking about the for loop, something like</p>

<pre><code>for(var i=0;i&lt;data.length;i++){
if(var i == doesnt exist){
code1 runs
}
else{
code2 runs
}
</code></pre>

<p>Heres the code in the html</p>

<pre><code>&lt;script&gt;
function funfacts(o){
    var facts = document.getElementById('funfacts');
    var data = o.query.results.a;
    for(var i=0;i&lt;data.length;i++){
        var out = document.createElement('a');
        facts.appendChild(out);
        out.href = data[i].href;
        out.innerHTML = data[i].alt;
        out.appendChild(document.createElement('br'));
    }
}
&lt;/script&gt;
</code></pre>
