jQuery API jQuery API 中英文对照版 - jQuery在线查询手册
$.merge(first, second)
$.merge(first,second)

合并两个数组,删除其中重复的项目。

得到的新数组是:第一个数组中的所有项目,加上第二个数组中唯一的(不与第一个数组中任何项目相同的)项目。

返回值:Array

参数:

  • first (Array): 要合并的第一个数组
  • second (Array): 要合并的第二个数组
 
示例:

合并两个数组,删除其中重复的2

$.merge( [0,1,2], [2,3,4] )

结果:

[0,1,2,3,4]

示例:

合并两个数组,删除重复的3和2。

$.merge( [3,2,1], [4,3,2] )

结果:

[3,2,1,4]

 
$.merge( first, second )

Merge two arrays together, removing all duplicates.

The result is the altered first argument with the unique elements from the second array added.

Return value: Array
Parameters:

  • first (Array): The first array to merge, the unique elements of second added.
  • second (Array): The second array to merge into the first, unaltered.
 

Example:

Merges two arrays, removing the duplicate 2

 $.merge( [0,1,2], [2,3,4] )  
Result:
 [0,1,2,3,4]  

Example:

Merges two arrays, removing the duplicates 3 and 2

 var array = [3,2,1];   $.merge( array, [4,3,2] )  
Result:
 array == [3,2,1,4]