<?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/"
		>
<channel>
	<title>Comments on: Advanced Javascript: Objects, Arrays, and Array-Like objects</title>
	<atom:link href="http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/feed/" rel="self" type="application/rss+xml" />
	<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/</link>
	<description>Expert Advice on Website Development, Javascript, Ajax, and Security</description>
	<lastBuildDate>Wed, 01 Feb 2012 22:13:59 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: JavaScript Interview Questions: Arrays &#124; JavaScript Mountain</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-5472</link>
		<dc:creator>JavaScript Interview Questions: Arrays &#124; JavaScript Mountain</dc:creator>
		<pubDate>Wed, 01 Feb 2012 06:26:19 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-5472</guid>
		<description>[...] Hint: JavaScript arrays are Objects [...]</description>
		<content:encoded><![CDATA[<p>[...] Hint: JavaScript arrays are Objects [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Quora</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-5470</link>
		<dc:creator>Quora</dc:creator>
		<pubDate>Mon, 30 Jan 2012 13:26:52 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-5470</guid>
		<description>&lt;strong&gt;Why do arrays work as objects in JavaScript?...&lt;/strong&gt;

go to this link:-http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/...</description>
		<content:encoded><![CDATA[<p><strong>Why do arrays work as objects in JavaScript?&#8230;</strong></p>
<p>go to this link:-http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nFriedly</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-5467</link>
		<dc:creator>nFriedly</dc:creator>
		<pubDate>Tue, 24 Jan 2012 08:41:28 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-5467</guid>
		<description>Yep, that&#039;s another good way to do it :)</description>
		<content:encoded><![CDATA[<p>Yep, that&#8217;s another good way to do it <img src='http://nfriedly.com/techblog/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mark</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-5465</link>
		<dc:creator>Mark</dc:creator>
		<pubDate>Mon, 23 Jan 2012 16:48:08 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-5465</guid>
		<description>Frank,

I would take a look at your design and see if objectArray could instead be an Object, and not an Array.  If so, I&#039;d change it&#039;s name to objectLookup, and then finding a module with &quot;attendanceindex&quot; is O(1).

 [js]   var objectLookup = {
       attendanceindex : 
         {
	        moduleKey: &quot;attendancecalendar&quot;,
	        iframe: true,
	        innerWidth: 500,
	        innerHeight: 350,
	        opacity: 0.35,
	        scrolling: false,
	        identifierType: &quot;href&quot;
	 },
         // ...rest of contents of objectArray
    };

    //then later..
    var winner = objectLookup.attendanceindex;[/js]</description>
		<content:encoded><![CDATA[<p>Frank,</p>
<p>I would take a look at your design and see if objectArray could instead be an Object, and not an Array.  If so, I&#8217;d change it&#8217;s name to objectLookup, and then finding a module with &#8220;attendanceindex&#8221; is O(1).</p>
<pre class="brush: jscript; title: ; notranslate">   var objectLookup = {
       attendanceindex :
         {
	        moduleKey: &quot;attendancecalendar&quot;,
	        iframe: true,
	        innerWidth: 500,
	        innerHeight: 350,
	        opacity: 0.35,
	        scrolling: false,
	        identifierType: &quot;href&quot;
	 },
         // ...rest of contents of objectArray
    };

    //then later..
    var winner = objectLookup.attendanceindex;</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: nFriedly</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-5140</link>
		<dc:creator>nFriedly</dc:creator>
		<pubDate>Wed, 18 Jan 2012 04:07:56 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-5140</guid>
		<description>Hi Frank,

There&#039;s no &quot;quick&quot; way to do it, you&#039;d just need to loop through the entire list and check each one until you find it:

[js]
var winner;
for(var i=0; i&lt; detailsArray.length; i++) {
  if(detailsArray[i].moduleKey === &quot;attendanceindex&quot;) {
    winner == detailsArray[i];
    break;
  }
}[/js]

Note, I said &quot;quick&quot; in quotes because in reality even with 1000 items in the array it took 0.005 seconds on my laptop (I tested it).</description>
		<content:encoded><![CDATA[<p>Hi Frank,</p>
<p>There&#8217;s no &#8220;quick&#8221; way to do it, you&#8217;d just need to loop through the entire list and check each one until you find it:</p>
<pre class="brush: jscript; title: ; notranslate">
var winner;
for(var i=0; i&lt; detailsArray.length; i++) {
  if(detailsArray[i].moduleKey === &quot;attendanceindex&quot;) {
    winner == detailsArray[i];
    break;
  }
}</pre>
<p>Note, I said &#8220;quick&#8221; in quotes because in reality even with 1000 items in the array it took 0.005 seconds on my laptop (I tested it).</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Frank</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-4892</link>
		<dc:creator>Frank</dc:creator>
		<pubDate>Tue, 17 Jan 2012 00:37:55 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-4892</guid>
		<description>Very coherent, well-expressed piece. I was hoping you might give me a pointer on how to find an object in an array of objects whose object property has a specified value. Fore example, if I have an array:
[js]     var detailsArray = [
        {
            moduleKey: &quot;attendancecalendar&quot;,
            iframe: true,
            innerWidth: 500,
            innerHeight: 350,
            opacity: 0.35,
            scrolling: false,
            identifierType: &quot;href&quot;
        },
        {
            moduleKey: &quot;attendanceindex&quot;,
            iframe: true,
            innerWidth: 500,
            innerHeight: 350,
            opacity: 0.35,
            scrolling: false,
            identifierType: &quot;href&quot;
        }
        //etc.
    ];[/js]
------
How would I find the object whose moduleKey is &quot;attendanceindex&quot;?
Thanks</description>
		<content:encoded><![CDATA[<p>Very coherent, well-expressed piece. I was hoping you might give me a pointer on how to find an object in an array of objects whose object property has a specified value. Fore example, if I have an array:</p>
<pre class="brush: jscript; title: ; notranslate">     var detailsArray = [
        {
            moduleKey: &quot;attendancecalendar&quot;,
            iframe: true,
            innerWidth: 500,
            innerHeight: 350,
            opacity: 0.35,
            scrolling: false,
            identifierType: &quot;href&quot;
        },
        {
            moduleKey: &quot;attendanceindex&quot;,
            iframe: true,
            innerWidth: 500,
            innerHeight: 350,
            opacity: 0.35,
            scrolling: false,
            identifierType: &quot;href&quot;
        }
        //etc.
    ];</pre>
<p>&#8212;&#8212;<br />
How would I find the object whose moduleKey is &#8220;attendanceindex&#8221;?<br />
Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Spencer</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-3354</link>
		<dc:creator>Spencer</dc:creator>
		<pubDate>Mon, 17 Oct 2011 19:56:47 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-3354</guid>
		<description>Very nice overview.  I&#039;ve been trying to brush up on my coding skills.  That made it much more clear for me.</description>
		<content:encoded><![CDATA[<p>Very nice overview.  I&#8217;ve been trying to brush up on my coding skills.  That made it much more clear for me.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Bug #1139 &#8211; Oops, my bad. &#124; The Open Source Experience</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-2946</link>
		<dc:creator>Bug #1139 &#8211; Oops, my bad. &#124; The Open Source Experience</dc:creator>
		<pubDate>Tue, 15 Mar 2011 13:35:16 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-2946</guid>
		<description>[...] code above accepts arguments such as array, objects, array-like objects. I found this site helpful when trying to understand objects, arrays and array-like objects. By changing the code to [...]</description>
		<content:encoded><![CDATA[<p>[...] code above accepts arguments such as array, objects, array-like objects. I found this site helpful when trying to understand objects, arrays and array-like objects. By changing the code to [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: nFriedly</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-158</link>
		<dc:creator>nFriedly</dc:creator>
		<pubDate>Wed, 22 Jul 2009 19:50:42 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-158</guid>
		<description>Hey Dmitriy! 

Yea, those are good points, both about arrays not getting their own type and forEach loops hitting inherited items as well as local items. It&#039;s handy when you want those inherited items to be in the loop though. 

Similarly, live collections can be really handy, as long as you realize they&#039;re live ;)</description>
		<content:encoded><![CDATA[<p>Hey Dmitriy! </p>
<p>Yea, those are good points, both about arrays not getting their own type and forEach loops hitting inherited items as well as local items. It&#8217;s handy when you want those inherited items to be in the loop though. </p>
<p>Similarly, live collections can be really handy, as long as you realize they&#8217;re live <img src='http://nfriedly.com/techblog/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
]]></content:encoded>
	</item>
	<item>
		<title>By: illvm</title>
		<link>http://nfriedly.com/techblog/2009/06/advanced-javascript-objects-arrays-and-array-like-objects/comment-page-1/#comment-103</link>
		<dc:creator>illvm</dc:creator>
		<pubDate>Tue, 14 Jul 2009 05:01:26 +0000</pubDate>
		<guid isPermaLink="false">http://nfriedly.com/techblog/?p=106#comment-103</guid>
		<description>There is no array type in JS though. All arrays are objects! typeof [] === &#039;object&#039;; Even more confusing is HTMLCollections appear to be arrays when they are, indeed not, and inherit from a separate prototype. On top of that they are live collections and need to be cloned or otherwise cached if you are modifying them in some way (especially adding to or removing from).

What&#039;s really unfortunate is that for in loops are deceptively not forEach loops. They iterate over every key in the object on the right side of the in without regard to whether that key is actually part of that object! I don&#039;t really see an issue with the for in loops using &#039;two&#039; as an index though, it seems proper. For in returning prototype keys instead of objects keys though can be a real mess. =/</description>
		<content:encoded><![CDATA[<p>There is no array type in JS though. All arrays are objects! typeof [] === &#8216;object&#8217;; Even more confusing is HTMLCollections appear to be arrays when they are, indeed not, and inherit from a separate prototype. On top of that they are live collections and need to be cloned or otherwise cached if you are modifying them in some way (especially adding to or removing from).</p>
<p>What&#8217;s really unfortunate is that for in loops are deceptively not forEach loops. They iterate over every key in the object on the right side of the in without regard to whether that key is actually part of that object! I don&#8217;t really see an issue with the for in loops using &#8216;two&#8217; as an index though, it seems proper. For in returning prototype keys instead of objects keys though can be a real mess. =/</p>
]]></content:encoded>
	</item>
</channel>
</rss>

