This method is like `union` except that it accepts `comparator` which is invoked to compare elements of `arrays`. Result values are chosen from the first array in which the value occurs. The comparator is invoked with two arguments: (arrVal, othVal).
const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]
unionWith(objects, others, isEqual)
// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
| Name | Type | Attribute | Description |
|---|---|---|---|
| arrays | The arrays to inspect. | ||
| comparator | The comparator invoked per element. |
{
"comment": "/**\r\n * This method is like `union` except that it accepts `comparator` which\r\n * is invoked to compare elements of `arrays`. Result values are chosen from\r\n * the first array in which the value occurs. The comparator is invoked\r\n * with two arguments: (arrVal, othVal).\r\n *\r\n * @since 4.0.0\r\n * @category Array\r\n * @param {...Array} [arrays] The arrays to inspect.\r\n * @param {Function} [comparator] The comparator invoked per element.\r\n * @returns {Array} Returns the new array of combined values.\r\n * @see difference, union, unionBy, without, xor, xorBy\r\n * @example\r\n *\r\n * const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]\r\n * const others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]\r\n *\r\n * unionWith(objects, others, isEqual)\r\n * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]\r\n */",
"meta": {
"range": [
1006,
1237
],
"filename": "unionWith.js",
"lineno": 26,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100011167",
"name": "unionWith",
"type": "FunctionDeclaration",
"paramnames": [
"arrays"
]
},
"vars": {
"comparator": "unionWith~comparator"
}
},
"description": "This method is like `union` except that it accepts `comparator` which\ris invoked to compare elements of `arrays`. Result values are chosen from\rthe first array in which the value occurs. The comparator is invoked\rwith two arguments: (arrVal, othVal).",
"since": "4.0.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Array",
"value": "Array"
}
],
"params": [
{
"type": {
"names": [
"Array"
]
},
"optional": true,
"variable": true,
"description": "The arrays to inspect.",
"name": "arrays"
},
{
"type": {
"names": [
"function"
]
},
"optional": true,
"description": "The comparator invoked per element.",
"name": "comparator"
}
],
"returns": [
{
"type": {
"names": [
"Array"
]
},
"description": "Returns the new array of combined values."
}
],
"see": [
"difference, union, unionBy, without, xor, xorBy"
],
"examples": [
"const objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]\rconst others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]\r\runionWith(objects, others, isEqual)\r// => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]"
],
"name": "unionWith",
"longname": "unionWith",
"kind": "function",
"scope": "global",
"___id": "T000002R001013",
"___s": true,
"filepath": "unionWith.js"
}