<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
> <channel><title>David Pratt &#187; recursion</title> <atom:link href="http://daipratt.co.uk/tag/recursion/feed/" rel="self" type="application/rss+xml" /><link>http://daipratt.co.uk</link> <description>Concerned about Website Construction &#38; SEO</description> <lastBuildDate>Thu, 17 May 2012 19:14:00 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Always cache the length property in for loops when using JavaScript</title><link>http://daipratt.co.uk/always-cache-the-length-property-in-for-loops-when-using-javascript/</link> <comments>http://daipratt.co.uk/always-cache-the-length-property-in-for-loops-when-using-javascript/#comments</comments> <pubDate>Tue, 26 Jan 2010 10:13:22 +0000</pubDate> <dc:creator>David Pratt</dc:creator> <category><![CDATA[Tech]]></category> <category><![CDATA[javascript]]></category> <category><![CDATA[performance]]></category> <category><![CDATA[recursion]]></category> <guid
isPermaLink="false">http://daipratt.co.uk/?p=1081</guid> <description><![CDATA[Well, you don't have to, but it helps a smidgen when it comes to performance...]]></description> <content:encoded><![CDATA[<p>To speed up <i>for loops</i> in JavaScript you should always look to cache the <i>length property</i> so that the value of this doesn&#8217;t have to be recalculated on every iteration of the loop.  There are a couple of ways to do this, the first and most obvious way is to calculate the array length outside of the loop e.g.</p><pre class="brush: javascript">
var l = bigArray.length;
for(var i = 0; i &lt; l; i++){
	//Do stuff
}
</pre><p>Another less well known way is to cache the length property in the for loop decleration e.g.</p><pre class="brush: javascript">
for(var i = 0, l = bigArray.length; i &lt; l; i++){
	//Do stuff
}
</pre>]]></content:encoded> <wfw:commentRss>http://daipratt.co.uk/always-cache-the-length-property-in-for-loops-when-using-javascript/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
