Skip navigation

Consider the below code

//
aAge = Array(31,23,42,44,25);  //1
aLength = aAge.length;  //2
for(i=0;i<aLength;i++)   //3
  alert(aAge[i]);   //3
//

How to avoid line number 2?

//
aAge = Array(31,23,42,44,25);  //1
for(i=0;i<aAge.length;i++)   //2
  alert(aAge[i]);   //3
//

But to avoid length calculation each iteration

//
aAge = Array(31,23,42,44,25);  //1
for(i=0,aLength=aAge.length;i< aLength;i++)   //2
  alert(aAge[i]);   //3
//

A cool trick!! May be useful to you guys!!!

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 95 other followers