<?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>array &#8211; stoimen&#039;s web log</title>
	<atom:link href="/tag/array/feed/" rel="self" type="application/rss+xml" />
	<link></link>
	<description>on web development</description>
	<lastBuildDate>Tue, 13 Feb 2018 08:18:15 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>Javascript Array Unique</title>
		<link>/2015/05/04/javascript-array-unique/</link>
		<comments>/2015/05/04/javascript-array-unique/#comments</comments>
		<pubDate>Mon, 04 May 2015 13:15:39 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[functional programming]]></category>
		<category><![CDATA[functions]]></category>
		<category><![CDATA[Method]]></category>

		<guid isPermaLink="false">/?p=3600</guid>
		<description><![CDATA[<div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2009/03/07/flex-javascript-communication/" rel="bookmark" title="Flex Javascript communication">Flex Javascript communication </a></li>
<li><a href="/2009/03/12/javascript-rounded-corners/" rel="bookmark" title="JavaScript rounded corners">JavaScript rounded corners </a></li>
<li><a href="/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/" rel="bookmark" title="Replace the Broken Images with a Default Image with JavaScript">Replace the Broken Images with a Default Image with JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><script src="https://gist.github.com/stoimen/c42dcc2d57f6f68c3941.js"></script></p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2009/03/07/flex-javascript-communication/" rel="bookmark" title="Flex Javascript communication">Flex Javascript communication </a></li>
<li><a href="/2009/03/12/javascript-rounded-corners/" rel="bookmark" title="JavaScript rounded corners">JavaScript rounded corners </a></li>
<li><a href="/2010/07/01/replace-the-broken-images-with-a-default-image-with-javascript/" rel="bookmark" title="Replace the Broken Images with a Default Image with JavaScript">Replace the Broken Images with a Default Image with JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2015/05/04/javascript-array-unique/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Using PHP&#8217;s array_diff in Algorithm Development</title>
		<link>/2010/10/03/using-php-array_diff-in-algorithm-development/</link>
		<comments>/2010/10/03/using-php-array_diff-in-algorithm-development/#comments</comments>
		<pubDate>Sun, 03 Oct 2010 10:51:54 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Control flow]]></category>
		<category><![CDATA[Data structures]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[Foreach]]></category>
		<category><![CDATA[Notation]]></category>

		<guid isPermaLink="false">/?p=2010</guid>
		<description><![CDATA[array_diff can be really powerful. Once you&#8217;ve to find the different elements between two arrays you&#8217;ve to use array_diff. Here&#8217;s a case when you can use it while coding a simple algorithm. The Task You&#8217;ve one array with tickets of linked destinations &#8211; so you start from one city to another, than next and so &#8230; <a href="/2010/10/03/using-php-array_diff-in-algorithm-development/" class="more-link">Continue reading <span class="screen-reader-text">Using PHP&#8217;s array_diff in Algorithm Development</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
<li><a href="/2011/10/19/thing-to-know-about-php-arrays/" rel="bookmark" title="Thing to Know About PHP Arrays">Thing to Know About PHP Arrays </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
<li><a href="/2010/08/29/beginning-algorithm-complexity-and-estimation/" rel="bookmark" title="Beginning Algorithm Complexity and Estimation">Beginning Algorithm Complexity and Estimation </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p><a title="PHP: array_diff" href="http://php.net/manual/en/function.array-diff.php" target="_blank">array_diff</a> can be really powerful. Once you&#8217;ve to find the different elements between two arrays you&#8217;ve to use array_diff. Here&#8217;s a case when you can use it while coding a simple algorithm.</p>
<h2>The Task</h2>
<p>You&#8217;ve one array with tickets of linked destinations &#8211; so you start from one city to another, than next and so on. Each element is an array with &#8220;from&#8221; and &#8220;to&#8221; destinations:</p>
<pre lang="php">
$inputTickets = array(
    0 => array('from' => 'barcelona', 'to' => 'madrid'),
    1 => array('from' => 'sofia', 'to' => 'paris'),
    2 => array('from' => 'madrid', 'to' => 'milano'),
    3 => array('from' => 'paris', 'to' => 'barcelona'),
    4 => array('from' => 'cupertino', 'to' => 'sofia'),
    5 => array('from' => 'milano', 'to' => 'valencia'),
    6 => array('from' => 'valencia', 'to' => 'nice'),
    7 => array('from' => 'mountain view', 'to' => 'cupertino'),
);
</pre>
<p>It&#8217;s easy to construct two arrays &#8211; the &#8220;from&#8221; destinations array and the &#8220;to&#8221; destinations array, and here the easiest way to get the starting point of the whole trip, because of the fact that these are linked tickets.</p>
<pre lang="php">
$fromDestinations = $toDestinations = array();

foreach ($inputTickets as $k => $v) {
    $fromDestinations[] = $v['from'];
    $toDestinations[]   = $v['to'];
}

// and finally get the starting point
$startPoint = array_diff($fromDestinations, $toDestinations);
</pre>
<h2>Conclusion</h2>
<p>Beside of knowing several algorithm techniques, there&#8217;s also need of knowing the language syntax and possibilities &#8211; in that case PHP&#8217;s</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" rel="bookmark" title="PHP: What is More Powerful Than list() &#8211; Perhaps extract()">PHP: What is More Powerful Than list() &#8211; Perhaps extract() </a></li>
<li><a href="/2011/10/19/thing-to-know-about-php-arrays/" rel="bookmark" title="Thing to Know About PHP Arrays">Thing to Know About PHP Arrays </a></li>
<li><a href="/2012/07/24/php-arrays-or-linked-lists/" rel="bookmark" title="PHP: Arrays or Linked Lists?">PHP: Arrays or Linked Lists? </a></li>
<li><a href="/2010/08/29/beginning-algorithm-complexity-and-estimation/" rel="bookmark" title="Beginning Algorithm Complexity and Estimation">Beginning Algorithm Complexity and Estimation </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/10/03/using-php-array_diff-in-algorithm-development/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP: What is More Powerful Than list() &#8211; Perhaps extract()</title>
		<link>/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/</link>
		<comments>/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 15:49:35 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Associative array]]></category>
		<category><![CDATA[Comparison of programming languages]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Data structures]]></category>
		<category><![CDATA[Data types]]></category>
		<category><![CDATA[post]]></category>

		<guid isPermaLink="false">/?p=1942</guid>
		<description><![CDATA[list() in PHP Recently I wrote about list() in PHP which is indeed very powerful when assigning variable values from array elements. $a = array(10, array('here', 'are', 'some', 'tests')); list($count, $list) = $a; Actually my example in the post was not correct, because I wrote that you can pass an associative array, but the truth &#8230; <a href="/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/" class="more-link">Continue reading <span class="screen-reader-text">PHP: What is More Powerful Than list() &#8211; Perhaps extract()</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2011/10/19/thing-to-know-about-php-arrays/" rel="bookmark" title="Thing to Know About PHP Arrays">Thing to Know About PHP Arrays </a></li>
<li><a href="/2010/09/29/construct-a-sorted-php-linked-list/" rel="bookmark" title="Construct a Sorted PHP Linked List">Construct a Sorted PHP Linked List </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>list() in PHP</h2>
<p>Recently I wrote <a title="PHP: what is more powerful than list" href="/2010/08/27/php-what-is-more-powerful-than-list/" target="_blank">about list()</a> in PHP which is indeed very powerful when assigning variable values from array elements.</p>
<pre lang="php">
$a = array(10, array('here', 'are', 'some', 'tests'));
list($count, $list) = $a;
</pre>
<p>Actually my example in the post was not correct, because I wrote that you can pass an associative array, but the truth is that you cannot, and thus the array should be always with numeric keys. After noticing the comments of that post, and thanks to @Philip,  I searched a bit about how this problem can be overcome.</p>
<h2>There is a Solution</h2>
<p>As always PHP gives a perfect solution! You can see on the <a title="PHP: list - Manual" href="http://php.net/manual/en/function.list.php" target="_blank">list() doc page</a> that there is a function that may help you use an associative array.</p>
<h2>Extract</h2>
<p>extract() is perhaps less known than list(), but it does the right thing!</p>
<pre lang="php">
$a = array('count' => 10, 'list' => array('here', 'are', 'some', 'tests'));
extract($a);

echo $count;    // 10
print_r($list); // array('here'....
</pre>
<p>Note that now both $count and $list are defined.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/08/27/php-what-is-more-powerful-than-list/" rel="bookmark" title="PHP: What is More Powerful Than list()">PHP: What is More Powerful Than list() </a></li>
<li><a href="/2011/10/19/thing-to-know-about-php-arrays/" rel="bookmark" title="Thing to Know About PHP Arrays">Thing to Know About PHP Arrays </a></li>
<li><a href="/2010/09/29/construct-a-sorted-php-linked-list/" rel="bookmark" title="Construct a Sorted PHP Linked List">Construct a Sorted PHP Linked List </a></li>
<li><a href="/2011/08/18/powerful-php-less-known-string-manipulation/" rel="bookmark" title="Powerful PHP: Less Known String Manipulation">Powerful PHP: Less Known String Manipulation </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/08/31/php-what-is-more-powerful-than-list-perhaps-extract/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>PHP Associative Arrays Coding Style</title>
		<link>/2010/05/19/php-associative-arrays-coding-style/</link>
		<comments>/2010/05/19/php-associative-arrays-coding-style/#comments</comments>
		<pubDate>Wed, 19 May 2010 14:14:03 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[C]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[Curly bracket programming languages]]></category>
		<category><![CDATA[Human Interest]]></category>
		<category><![CDATA[Initialisms]]></category>
		<category><![CDATA[PHAML]]></category>
		<category><![CDATA[PHP programmer]]></category>
		<category><![CDATA[PHP programming language]]></category>
		<category><![CDATA[Procedural programming languages]]></category>
		<category><![CDATA[Software engineering]]></category>
		<category><![CDATA[Technology/Internet]]></category>
		<category><![CDATA[zend framework]]></category>

		<guid isPermaLink="false">/?p=1532</guid>
		<description><![CDATA[No PHP programmer writes code without arrays. Sound strange, but as many programmers there are, as many ways to format the array notation there are. My advice is to rely on a defined standard. I personally use the Zend Framework&#8217;s coding style. So how to format the code? The first way is on the same &#8230; <a href="/2010/05/19/php-associative-arrays-coding-style/" class="more-link">Continue reading <span class="screen-reader-text">PHP Associative Arrays Coding Style</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/12/03/javascript-objects-coding-style-reviewed/" rel="bookmark" title="JavaScript Objects Coding Style Reviewed">JavaScript Objects Coding Style Reviewed </a></li>
<li><a href="/2010/05/25/php-coding-style-large-if-statements/" rel="bookmark" title="PHP Coding Style: Large IF Statements">PHP Coding Style: Large IF Statements </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2010/05/26/php-conditionals-coding-style/" rel="bookmark" title="PHP: Conditionals Coding Style">PHP: Conditionals Coding Style </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<p>No PHP programmer writes code without arrays. Sound strange, but as many programmers there are, as many ways to format the array notation there are.</p>
<p>My advice is to rely on a defined standard. I personally use the Zend Framework&#8217;s coding style.</p>
<p>So how to format the code? The first way is on the same line:</p>
<pre lang="php" escaped="true">$myArray = array('key1' =&gt; 'value1',
		 'key2' =&gt; 'value2');
</pre>
<p>And the other, perhaps more clear way is to place the associative pairs on a new line:</p>
<pre lang="php" escaped="true">$myArray = array(
	'key1' =&gt; 'value1',
	'key2' =&gt; 'value2',
);
</pre>
<p>Note that in the second example there&#8217;s a comma after the second pair. This is correct PHP syntax and is strongly encouraged!</p>
<p>It&#8217;s up to you which way to take. However it mainly depends on the case, but please use standards.</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/12/03/javascript-objects-coding-style-reviewed/" rel="bookmark" title="JavaScript Objects Coding Style Reviewed">JavaScript Objects Coding Style Reviewed </a></li>
<li><a href="/2010/05/25/php-coding-style-large-if-statements/" rel="bookmark" title="PHP Coding Style: Large IF Statements">PHP Coding Style: Large IF Statements </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
<li><a href="/2010/05/26/php-conditionals-coding-style/" rel="bookmark" title="PHP: Conditionals Coding Style">PHP: Conditionals Coding Style </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/05/19/php-associative-arrays-coding-style/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Array merge in JavaScript</title>
		<link>/2010/01/21/array-merge-in-javascript/</link>
		<comments>/2010/01/21/array-merge-in-javascript/#comments</comments>
		<pubDate>Thu, 21 Jan 2010 18:22:28 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[micro tutorial]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[Computer programming]]></category>
		<category><![CDATA[Computer science]]></category>
		<category><![CDATA[Computing]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[Sorting algorithms]]></category>
		<category><![CDATA[Trim]]></category>

		<guid isPermaLink="false">/?p=852</guid>
		<description><![CDATA[What makes array to merge in JavaScript? Actually there aren’t so many array functions in JavaScript. As you know you can join, sort, etc. which methods are pretty basic. What I’d like to do is something similar to PHPs’ array_merge and than array_unique. With JavaScript that seems pretty impossible. You can merge them with the &#8230; <a href="/2010/01/21/array-merge-in-javascript/" class="more-link">Continue reading <span class="screen-reader-text">Array merge in JavaScript</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/06/14/javascript-array-pop-get-the-last-item/" rel="bookmark" title="JavaScript array.pop() &#8211; Get The Last Item">JavaScript array.pop() &#8211; Get The Last Item </a></li>
<li><a href="/2010/07/02/friday-algorithms-javascript-merge-sort/" rel="bookmark" title="Friday Algorithms: JavaScript Merge Sort">Friday Algorithms: JavaScript Merge Sort </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/01/09/array-hint-in-javascript/" rel="bookmark" title="Array hint in JavaScript">Array hint in JavaScript </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>What makes array to merge in JavaScript?</h2>
<p>Actually there aren’t so many array functions in JavaScript. As you know you can join, sort, etc. which methods are pretty basic. What I’d like to do is something similar to PHPs’ array_merge and than array_unique.</p>
<p>With JavaScript that seems pretty impossible. You can merge them with the .concat function as in the example bellow:</p>
<blockquote>
<pre>var a = [1,2];
var b = [3,4];
a.concat(b);</pre>
</blockquote>
<p>this gives you array with four elements. But when it comes to trim all the duplicates as it’s array_unique in PHP, well that’s really impossible. You’ve to do it by yourself, and I don’t thing this is the best technique. That slows down the code and you should avoid it!</p>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/06/14/javascript-array-pop-get-the-last-item/" rel="bookmark" title="JavaScript array.pop() &#8211; Get The Last Item">JavaScript array.pop() &#8211; Get The Last Item </a></li>
<li><a href="/2010/07/02/friday-algorithms-javascript-merge-sort/" rel="bookmark" title="Friday Algorithms: JavaScript Merge Sort">Friday Algorithms: JavaScript Merge Sort </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/01/09/array-hint-in-javascript/" rel="bookmark" title="Array hint in JavaScript">Array hint in JavaScript </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/01/21/array-merge-in-javascript/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Array hint in JavaScript</title>
		<link>/2010/01/09/array-hint-in-javascript/</link>
		<comments>/2010/01/09/array-hint-in-javascript/#respond</comments>
		<pubDate>Sat, 09 Jan 2010 07:08:25 +0000</pubDate>
		<dc:creator><![CDATA[Stoimen]]></dc:creator>
				<category><![CDATA[javascript]]></category>
		<category><![CDATA[web development]]></category>
		<category><![CDATA[array]]></category>
		<category><![CDATA[JavaScript programming language]]></category>
		<category><![CDATA[JavaScript syntax]]></category>

		<guid isPermaLink="false">/?p=853</guid>
		<description><![CDATA[new vs [] There are two ways to make new instance of a JavaScript array. As the previous sentence says one of them is by using the new operator. Actually even if you&#8217;re not familiar with JavaScript you&#8217;ve probably heart something about &#8220;new&#8221; from some other programming language, as it is very common to appear &#8230; <a href="/2010/01/09/array-hint-in-javascript/" class="more-link">Continue reading <span class="screen-reader-text">Array hint in JavaScript</span> <span class="meta-nav">&#8594;</span></a><div class='yarpp-related-rss'>

Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2010/06/14/javascript-array-pop-get-the-last-item/" rel="bookmark" title="JavaScript array.pop() &#8211; Get The Last Item">JavaScript array.pop() &#8211; Get The Last Item </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
</ol>
</div>
]]></description>
				<content:encoded><![CDATA[<h2>new vs []</h2>
<p>There are two ways to make new instance of a JavaScript array. As the previous sentence says one of them is by using the new operator. Actually even if you&#8217;re not familiar with JavaScript you&#8217;ve probably heart something about &#8220;new&#8221; from some other programming language, as it is very common to appear in almost every one. The way you make new instance is simply by:</p>
<blockquote>
<pre>var arr = new Array();</pre>
</blockquote>
<p>That seems pretty natural. The other way to make new instance, probably with some basic initialization is by using:</p>
<blockquote>
<pre>var arr = [];
// or if you'd like to put some predefined
// values into the array
// on init time
var arr = ['val1','val2'];</pre>
</blockquote>
<p>The reason I write this post is because as it seems the second way to instantiate an array in JavaScript is faster. That even if it seems funny is really important, because in modern, cool sites there&#8217;s a lot of JavaScript and probably there are thousands of &#8220;new Array()&#8221;&#8216;s which replaced by the simple &#8220;arr = []&#8221; may result in faster and more user fiendly site!</p>
<p>So use:</p>
<blockquote>
<pre>var arr = [];</pre>
</blockquote>
<div class='yarpp-related-rss'>
<p>Related posts:<ol>
<li><a href="/2010/01/21/array-merge-in-javascript/" rel="bookmark" title="Array merge in JavaScript">Array merge in JavaScript </a></li>
<li><a href="/2010/06/14/javascript-array-pop-get-the-last-item/" rel="bookmark" title="JavaScript array.pop() &#8211; Get The Last Item">JavaScript array.pop() &#8211; Get The Last Item </a></li>
<li><a href="/2010/06/11/friday-algorithms-quicksort-difference-between-php-and-javascript/" rel="bookmark" title="Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript">Friday Algorithms: Quicksort &#8211; Difference Between PHP and JavaScript </a></li>
<li><a href="/2010/05/24/javascript-objects-coding-style/" rel="bookmark" title="JavaScript Objects Coding Style">JavaScript Objects Coding Style </a></li>
</ol></p>
</div>
]]></content:encoded>
			<wfw:commentRss>/2010/01/09/array-hint-in-javascript/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
