jQuery.merge(first, second) (alias $.merge) appends items from second onto the end of first, preserves order, and returns the updated first array (since jQuery 1.0).
Pass two array-like values; second is appended onto first.
Prepare first (the array that will grow) and second (source to append).
Call $.merge(first, second).
Use the returned array (same reference as first).
If you must keep first unchanged, merge into a clone: $.merge($.merge([], first), second).
Piece
Required?
Role
first
Yes
Target array-like — modified in place
second
Yes
Items to append — left unaltered
Return
—
The merged first array
Pseudocode
Pseudocode
function merge(first, second):
for each item in second:
append item to first
update first.length
return first
// Official clone shortcut:
newArray = merge([], oldArray)
// Official safe combine:
result = merge(merge([], first), second)
Reference
Cheat Sheet
Keep these facts handy while combining arrays.
Topic
Detail
Syntax
jQuery.merge(first, second)
Since
jQuery 1.0
Mutates?
Yes — first only
Order
Preserved; second appended
Duplicates
Kept (not unique)
Clone
$.merge([], arr)
Pre-1.4
True arrays; else $.makeArray
Try it
Live Preview
Run official-style $.merge demos: append, clone, or safe combine.
Browser demo of $.merge() — same idea as the examples below.
Why merge. Useful when you intentionally want one mutable list.
Edge Cases & Pitfalls
Check these before merging arrays in real projects.
mutate
First array is modified
Always treat first as mutated. Clone first if callers still need the original list.
dupes
Duplicates are kept
Merge is not unique. Use $.uniqueSort() only for DOM node arrays when you need document-order uniqueness.
vs extend
Not for plain objects
Object key merges belong to $.extend(). $.merge appends indexed items.
legacy
Pre-1.4 needs true arrays
Older jQuery required real arrays. Convert with $.makeArray() when supporting very old builds.
Compatibility
Browser Support
jQuery.merge() needs jQuery in the browser. It has been available since jQuery 1.0+ in all browsers your jQuery build supports. Array-like arguments are accepted in modern jQuery (1.4+).
✓ jQuery 1.0+ · Browsers
jQuery.merge()
Works in Chrome, Firefox, Safari, Edge, and other browsers with jQuery loaded. Append array-like collections into the first array in place.
100%Browser support
Google ChromeAll versions · Desktop & Mobile
Full support
Mozilla FirefoxAll versions · Desktop & Mobile
Full support
Apple SafariAll versions · macOS & iOS
Full support
Microsoft EdgeAll versions · Chromium & Legacy
Full support
Internet ExplorerIE 6+ · Legacy environments
Full support
OperaAll modern versions
Full support
$.merge()Browsers
Bottom line: Use $.merge(first, second) to append in place — clone with $.merge([], arr) when you need a copy.
Analysis
Performance Notes
Approach
Cost
Best for
$.merge(a, b)
O(|b|)
In-place append / accumulators
a.concat(b)
O(|a|+|b|)
Immutable combine
$.merge([], a)
O(|a|)
Shallow clone
Prefer in-place merge when building one growing list. Prefer concat when immutability matters more than reuse of the first array.
Remember
Key Takeaways
Role:$.merge(first, second) appends onto first.
Destructive: only first changes; second is untouched.
Clone:$.merge([], arr) or nest merges for a safe combine.
Not unique: duplicates are kept; order is preserved.
One line:$.merge(first, second) appends second onto first in place — clone first when you need the original.
Frequently Asked Questions
jQuery.merge(first, second) appends all elements from the second array-like object onto the end of the first. It modifies the first array in place, updates its length, and returns the merged first array. The second array is left unchanged.
concat() returns a new array without modifying either source. $.merge() is destructive — it alters the first array. Use $.merge([], arr) or concat when you need to preserve the original first array.
jQuery.extend() merges object properties by key. jQuery.merge() appends array elements by index — it concatenates two array-like collections, not plain object key/value pairs.
Clone first with an empty array: var result = $.merge($.merge([], first), second). The nested pattern copies first into a new array, then appends second.
Yes. Both arguments can be array-like objects with a length property and indexed values — not just true arrays. Prior to jQuery 1.4, use $.makeArray() to convert non-array collections first.