Access data of objects through IDs dynamically
<p>I have an array as shown below which represents the ids of objects in the body of the HTML body:  </p>

<pre><code>var p=new Array ("p1" ,"p2" ,"p3" ,"p4" ,"p5","p6","p7","p8","p9","p10","p11" ,"p12","p13", "p14","p15","p16","p17","p18","p19","p20");
</code></pre>

<p>i need to iterate over those objects and retrieve their data, and i'm doing this in the following way which is not working:  </p>

<pre><code>for(var i=0; i&lt;20; i++)
        {
           var price=p[i].innerHTML;
           if(price.length != 7)
           {
             alert("yes");
           }
        }
</code></pre>

<p>What is the correct way to do what i'm trying to do? Thanks in advance.</p>
