jquery-mobile/experiments/api-viewer/docs/jQuery.merge/index.html
2010-11-01 21:46:29 -04:00

60 lines
No EOL
2.8 KiB
HTML

<!DOCTYPE html>
<html lang='en'><head>
<meta charset="utf-8" /><meta http-equiv='content-type' content='text/html; charset=UTF-8' /></head><body>
<div data-role="page">
<div data-role="header">
<h1>jQuery.merge()</h1>
</div>
<div data-role="content" data-theme="c" id="jQuery.merge1">
<h2 class="jq-clearfix roundTop section-title">
<span class="name">jQuery.merge( first, second )</span> <span class="returns">Returns: <a class="return" href="http://docs.jquery.com/Types#Array">Array</a></span>
</h2>
<div class=" entry-details">
<p class="desc"><strong>Description: </strong>Merge the contents of two arrays together into the first array. </p>
<ul class="signatures"><li class="signature" id="jQuery.merge-first-second">
<h4 class="name">
<span class="versionAdded">version added: <a href="/category/version/1.0/">1.0</a></span>jQuery.merge( first, second )</h4>
<p class="arguement"><strong>first</strong>The first array to merge, the elements of second added.</p>
<p class="arguement"><strong>second</strong>The second array to merge into the first, unaltered.</p>
</li></ul>
<div class="longdesc">
<p>The <code>$.merge()</code> operation forms an array that contains all elements from the two arrays. The orders of items in the arrays are preserved, with items from the second array appended. The <code>$.merge()</code> function is destructive. It alters the first parameter to add the items from the second. </p>
<p>If you need the original first array, make a copy of it before calling <code>$.merge()</code>. Fortunately, <code>$.merge()</code> itself can be used for this duplication:</p>
<pre>var newArray = $.merge([], oldArray);</pre>
<p>This shortcut creates a new, empty array and merges the contents of oldArray into it, effectively cloning the array.</p>
<p>The arguments should be true Javascript Array objects; use <code>$.makeArray</code> if they are not.</p>
</div>
<h3>Examples:</h3>
<div id="entry-examples" class="entry-examples">
<div id="example-0">
<h4>Example: <span class="desc">Merges two arrays, altering the first argument.</span>
</h4>
<pre><code class="example">$.merge( [0,1,2], [2,3,4] )</code></pre>
<h4>Result:</h4>
<pre><code class="results">[0,1,2,2,3,4] </code></pre>
</div>
<div id="example-1">
<h4>Example: <span class="desc">Merges two arrays, altering the first argument.</span>
</h4>
<pre><code class="example">$.merge( [3,2,1], [4,3,2] ) </code></pre>
<h4>Result:</h4>
<pre><code class="results">[3,2,1,4,3,2] </code></pre>
</div>
<div id="example-2">
<h4>Example: <span class="desc">Merges two arrays, but uses a copy, so the original isn't altered.</span>
</h4>
<pre><code class="example">var first = ['a','b','c'];
var second = ['d','e','f'];
$.merge( $.merge([],first), second);
</code></pre>
<h4>Result:</h4>
<pre><code class="results">["a","b","c","d","e","f"] </code></pre>
</div>
</div>
</div>
</div>
</div>
</body></html>