<?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: Array merge in JavaScript</title>
	<atom:link href="/2010/01/21/array-merge-in-javascript/feed/" rel="self" type="application/rss+xml" />
	<link>/2010/01/21/array-merge-in-javascript/</link>
	<description>on web development</description>
	<lastBuildDate>Fri, 26 Oct 2018 21:40:18 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>https://wordpress.org/?v=5.0.3</generator>
	<item>
		<title>By: Chris Huang</title>
		<link>/2010/01/21/array-merge-in-javascript/comment-page-1/#comment-438868</link>
		<dc:creator><![CDATA[Chris Huang]]></dc:creator>
		<pubDate>Wed, 18 Jan 2017 20:15:37 +0000</pubDate>
		<guid isPermaLink="false">/?p=852#comment-438868</guid>
		<description><![CDATA[James Heo&#039;s solution is not exacty the .concat() is doing.  .concat() it&#039;s more of using Array.prototype.push() with loop from b[0] to b[b.length-1] instead.

The reason James Heo&#039;s short hand version seems to be logical and short, but it involved array a and array b cast to a string first. Then apply string method to split again back to array.

the .push() method will be quicker because it doesn&#039;t have to go through array a again. It starts to push element one by one depend on the array b&#039;s total length instead.

Also.. both.. does not help for uniqueness.  If you are going to deal with conversion first, converts into hash which will automatically give you the uniqueness.

function concate(a, b) {
	var obj = {}, result = [];

	for(var i=0;i&#060;b.length;i++) {
		a.push(b[i]);  // merge b into a. This is = a.concate(b);
	}

	for(var i=0;i&#060;a.length;i++) {
		obj[a[i]] = a[i];	// find uniqueness
	}

	for (prop in obj) {		// converts obj to array
		if (hasOwnProperty.call(obj, prop)) {
			result.push(obj[prop]);
		}
	}
	
	return result;
}

var a = [34, 203, 3, 746, 200, 984, 198, 764, 9];
var b = [1,3,5,7,8,9,203,200];

console.log(concate(a,b));]]></description>
		<content:encoded><![CDATA[<p>James Heo&#8217;s solution is not exacty the .concat() is doing.  .concat() it&#8217;s more of using Array.prototype.push() with loop from b[0] to b[b.length-1] instead.</p>
<p>The reason James Heo&#8217;s short hand version seems to be logical and short, but it involved array a and array b cast to a string first. Then apply string method to split again back to array.</p>
<p>the .push() method will be quicker because it doesn&#8217;t have to go through array a again. It starts to push element one by one depend on the array b&#8217;s total length instead.</p>
<p>Also.. both.. does not help for uniqueness.  If you are going to deal with conversion first, converts into hash which will automatically give you the uniqueness.</p>
<p>function concate(a, b) {<br />
	var obj = {}, result = [];</p>
<p>	for(var i=0;i&lt;b.length;i++) {<br />
		a.push(b[i]);  // merge b into a. This is = a.concate(b);<br />
	}</p>
<p>	for(var i=0;i&lt;a.length;i++) {<br />
		obj[a[i]] = a[i];	// find uniqueness<br />
	}</p>
<p>	for (prop in obj) {		// converts obj to array<br />
		if (hasOwnProperty.call(obj, prop)) {<br />
			result.push(obj[prop]);<br />
		}<br />
	}</p>
<p>	return result;<br />
}</p>
<p>var a = [34, 203, 3, 746, 200, 984, 198, 764, 9];<br />
var b = [1,3,5,7,8,9,203,200];</p>
<p>console.log(concate(a,b));</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: James Heo</title>
		<link>/2010/01/21/array-merge-in-javascript/comment-page-1/#comment-14437</link>
		<dc:creator><![CDATA[James Heo]]></dc:creator>
		<pubDate>Mon, 03 Oct 2011 11:52:04 +0000</pubDate>
		<guid isPermaLink="false">/?p=852#comment-14437</guid>
		<description><![CDATA[var a = [1,2];
var b = [3,4];
var c=(a+&#039;,&#039;+b).split(&#039;,&#039;);

c equal to a.concat(b)]]></description>
		<content:encoded><![CDATA[<p>var a = [1,2];<br />
var b = [3,4];<br />
var c=(a+&#8217;,&#8217;+b).split(&#8216;,&#8217;);</p>
<p>c equal to a.concat(b)</p>
]]></content:encoded>
	</item>
</channel>
</rss>
