control-freak-ide/Control-Freak-Documentation/jQuery/docs/entries/jQuery.merge.json
plastic-hub-dev-node-saturn 538369cff7 latest
2021-05-12 18:35:18 +02:00

1 line
1.9 KiB
JSON

{"name":"jQuery.merge","type":"method","title":"jQuery.merge()","deprecated":null,"removed":null,"desc":"Merge the contents of two arrays together into the first array. ","categories":["utilities","version/1.0"],"entries":[{"return":"Array","signatures":{"added":"1.0","argument":[{"desc":"The first array to merge, the elements of second added.","name":"first","type":"Array"},{"desc":"The second array to merge into the first, unaltered.","name":"second","type":"Array"}]},"examples":[{"desc":"Merges two arrays, altering the first argument.","code":"\n$.merge( [ 0, 1, 2 ], [ 2, 3, 4 ] )\n","results":"\n[ 0, 1, 2, 2, 3, 4 ]\n"},{"desc":"Merges two arrays, altering the first argument.","code":"\n$.merge( [ 3, 2, 1 ], [ 4, 3, 2 ] )\n","results":"\n[ 3, 2, 1, 4, 3, 2 ]\n"},{"desc":"Merges two arrays, but uses a copy, so the original isn't altered.","code":"\nvar first = [ \"a\", \"b\", \"c\" ];\nvar second = [ \"d\", \"e\", \"f\" ];\n$.merge( $.merge( [], first ), second );\n","results":"\n[ \"a\", \"b\", \"c\", \"d\", \"e\", \"f\" ]\n"}],"longdesc":"\n <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>\n <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>\n <pre><code>\nvar newArray = $.merge([], oldArray);\n </code></pre>\n <p>This shortcut creates a new, empty array and merges the contents of oldArray into it, effectively cloning the array.</p>\n <p>Prior to jQuery 1.4, the arguments should be true Javascript Array objects; use <code>$.makeArray</code> if they are not.</p>\n "}]}