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).
Syntax
Start with these common calls. Keep them short and readable.
Copy. Items from original are appended into that new array.
Separate.copy === original is false.
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.