<?xml version="1.0" encoding="UTF-8"?><rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
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:series="http://unfoldingneurons.com/"
> <channel><title>Comments on: Implementing an Array.count() Method in&#160;JavaScript</title> <atom:link href="http://davidwalsh.name/implementing-array-count-method-javascript/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name/implementing-array-count-method-javascript</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Thu, 09 Feb 2012 15:40:33 +0000</lastBuildDate> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3</generator> <item><title>By: Patrick</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-27434</link> <dc:creator>Patrick</dc:creator> <pubDate>Thu, 03 Nov 2011 15:03:09 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-27434</guid> <description>I think it&#039;s okay for personal project but it has a counter side when you are in enterprise. The maintainability is harder when people use custom extension (prototype existing framework object). It cane be confusing. In some case, I have seen people creating function to simply get an object inside an array. I think this should be used with parsimony. But, it&#039;s just my opinion...</description> <content:encoded><![CDATA[<p>I think it&#8217;s okay for personal project but it has a counter side when you are in enterprise. The maintainability is harder when people use custom extension (prototype existing framework object). It cane be confusing. In some case, I have seen people creating function to simply get an object inside an array. I think this should be used with parsimony. But, it&#8217;s just my opinion&#8230;</p> ]]></content:encoded> </item> <item><title>By: Everwebby</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-27116</link> <dc:creator>Everwebby</dc:creator> <pubDate>Tue, 04 Oct 2011 13:49:19 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-27116</guid> <description>Riv, thats a much better form of the count use. Its surprising that this is not built into javascript.</description> <content:encoded><![CDATA[<p>Riv, thats a much better form of the count use. Its surprising that this is not built into javascript.</p> ]]></content:encoded> </item> <item><title>By: Christian</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-27007</link> <dc:creator>Christian</dc:creator> <pubDate>Tue, 27 Sep 2011 16:43:11 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-27007</guid> <description>Array.prototype.count = function () {
for (k in this) { if (this[k].constructor !== Function) { this.length++; } };
return this.length;
}</description> <content:encoded><![CDATA[<p>Array.prototype.count = function () {<br
/> for (k in this) { if (this[k].constructor !== Function) { this.length++; } };<br
/> return this.length;<br
/> }</p> ]]></content:encoded> </item> <item><title>By: riv</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-8533</link> <dc:creator>riv</dc:creator> <pubDate>Fri, 03 Apr 2009 01:30:48 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-8533</guid> <description>That&#039;s right and that&#039;s what I was expecting when searching for count on js. This should do it:function count(array)
{
var c = 0;
for(i in array) // in returns key, not object
if(array[i] != undefined)
c++;return c;}</description> <content:encoded><![CDATA[<p>That&#8217;s right and that&#8217;s what I was expecting when searching for count on js. This should do it:</p><p>function count(array)<br
/> {<br
/> var c = 0;<br
/> for(i in array) // in returns key, not object<br
/> if(array[i] != undefined)<br
/> c++;</p><p>return c;</p><p>}</p> ]]></content:encoded> </item> <item><title>By: Jason</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-3481</link> <dc:creator>Jason</dc:creator> <pubDate>Sun, 19 Oct 2008 17:27:16 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-3481</guid> <description>Correction to my previous post:the second code snippet would be:var myOtherArray = [];
myOtherArray[100] = &#039;one&#039;;and its length property would actually return 101.</description> <content:encoded><![CDATA[<p>Correction to my previous post:</p><p>the second code snippet would be:</p><p>var myOtherArray = [];<br
/> myOtherArray[100] = &#8216;one&#8217;;</p><p>and its length property would actually return 101.</p> ]]></content:encoded> </item> <item><title>By: Jason</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-3480</link> <dc:creator>Jason</dc:creator> <pubDate>Sun, 19 Oct 2008 17:23:38 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-3480</guid> <description>This is all fine and well, but length is fundamentally different from count.Take the following example:var myArray =  [&#039;one&#039;, &#039;two&#039;, &#039;three&#039;];
// myArray.length == 3, as we would expectvar myOtherArray[100] = &#039;one&#039;;
//myArray.length == 100, NOT 1Even though we only have 1 item in the array, &#039;length&#039; refers to the largest index + 1. Unlike PHP where we can use numeric keys and strings for indexes in an ad hoc way and still get an accurate count via count(), in JS it&#039;s not quite the same.In a way, this is just splitting hairs, but a lot of people already don&#039;t understand JS&#039;s length property, and referring to it as &quot;count&quot; only serves to further the confusion.</description> <content:encoded><![CDATA[<p>This is all fine and well, but length is fundamentally different from count.</p><p>Take the following example:</p><p>var myArray =  ['one', 'two', 'three'];<br
/> // myArray.length == 3, as we would expect</p><p>var myOtherArray[100] = &#8216;one&#8217;;<br
/> //myArray.length == 100, NOT 1</p><p>Even though we only have 1 item in the array, &#8216;length&#8217; refers to the largest index + 1. Unlike PHP where we can use numeric keys and strings for indexes in an ad hoc way and still get an accurate count via count(), in JS it&#8217;s not quite the same.</p><p>In a way, this is just splitting hairs, but a lot of people already don&#8217;t understand JS&#8217;s length property, and referring to it as &#8220;count&#8221; only serves to further the confusion.</p> ]]></content:encoded> </item> <item><title>By: david</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-1947</link> <dc:creator>david</dc:creator> <pubDate>Thu, 26 Jun 2008 03:33:03 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-1947</guid> <description>&lt;p&gt;@Binny:  No, I don&#039;t.  Just arrays.&lt;/p&gt;</description> <content:encoded><![CDATA[<p>@Binny:  No, I don&#8217;t.  Just arrays.</p> ]]></content:encoded> </item> <item><title>By: Binny V A</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-1935</link> <dc:creator>Binny V A</dc:creator> <pubDate>Wed, 25 Jun 2008 17:32:21 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-1935</guid> <description>Do you do this for strings as well?</description> <content:encoded><![CDATA[<p>Do you do this for strings as well?</p> ]]></content:encoded> </item> <item><title>By: Rich</title><link>http://davidwalsh.name/implementing-array-count-method-javascript/comment-page-1#comment-1923</link> <dc:creator>Rich</dc:creator> <pubDate>Wed, 25 Jun 2008 14:27:16 +0000</pubDate> <guid
isPermaLink="false">http://davidwalsh.name/?p=299#comment-1923</guid> <description>Thanks for your blog. you offer great advice and tutorials and for some odd reason, if I am looking to see how to complete a task, you have a tutorial on it or at least an idea on the concept I am trying to achieve; so thanks David. Although this post came about 2 days too late. :)</description> <content:encoded><![CDATA[<p>Thanks for your blog. you offer great advice and tutorials and for some odd reason, if I am looking to see how to complete a task, you have a tutorial on it or at least an idea on the concept I am trying to achieve; so thanks David. Although this post came about 2 days too late. :)</p> ]]></content:encoded> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 1/17 queries in 0.009 seconds using disk: basic
Object Caching 800/803 objects using disk: basic

Served from: davidwalsh.name @ 2012-02-09 12:06:12 -->
