<?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>Claudio&#039;s Hideout &#187; array</title>
	<atom:link href="http://claudio.cicali.name/post/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link>http://claudio.cicali.name</link>
	<description>Claudio Cicali web hub</description>
	<lastBuildDate>Sun, 25 Sep 2011 11:29:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>JavaScript and associative arrays don’t mix</title>
		<link>http://claudio.cicali.name/post/2007/07/javascript-and-associative-arrays-don%e2%80%99t-mix/</link>
		<comments>http://claudio.cicali.name/post/2007/07/javascript-and-associative-arrays-don%e2%80%99t-mix/#comments</comments>
		<pubDate>Thu, 12 Jul 2007 14:50:50 +0000</pubDate>
		<dc:creator>claudio</dc:creator>
				<category><![CDATA[Programmazione]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[javascript]]></category>

		<guid isPermaLink="false">http://claudio.cicali.name/?p=135</guid>
		<description><![CDATA[The concept of “associative arrays” is an alien, in the JavaScript world. I hear you “No, I’ve used them and they work”. My answer is “No, you have MISused something that looks like an associative array”. Let me explain. When you write something like… var friend = []; friend['name']='Claudio'; friend['age']='40'; …you’re creating an empty array [...]]]></description>
			<content:encoded><![CDATA[<p>The concept of “associative arrays” is an alien, in the JavaScript world.</p>
<p>I hear you “No, I’ve used them and they work”. My answer is “No, you have MISused something that looks like an associative array”.</p>
<p>Let me explain. When you write something like…</p>
<pre class="source">var friend = [];
friend['name']='Claudio';
friend['age']='40';</pre>
<p>…you’re creating an empty array (friend), and then you’re extending the <em>friend</em> <em>object</em> adding two properties (“name” and “surname”) to it. You were telling JavaScript that you’ll going to use an object with an indexed access (the array…), but then you use it as a simple object. Not fair.</p>
<p>You’d probably want to create something like this:</p>
<pre class="source">var friend = {}; // or new Object();
friend['name']='Claudio';
friend['age']='40';</pre>
<p>Your “associative array” is now a semantically correct JavaScript object.</p>
<p>Let’s look at a final example:</p>
<pre class="source">var friend = {}; // or new Object();
friend['name']='Claudio';
friend['age']='40';

// Properties can also be accessed with the dot notation
friend.name='Claudio';
friend.age='40';

// When using arrays, you're using something that is numerically indexed
var friend = []; // *or new Array();*
friend[0]='Claudio';
friend[1]='40';

// See? :)</pre>
<p>HTH</p>
]]></content:encoded>
			<wfw:commentRss>http://claudio.cicali.name/post/2007/07/javascript-and-associative-arrays-don%e2%80%99t-mix/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

