Lodash _.xorBy() Method

The _.xorBy method is similar to _.xor() method except that it accepts iteratee which is invoked for each element of each arrays to generate the criterion by which they are compared. Order of result values which is determined by the order they occur in the arrays.
Syntax:
_.xorBy(arrays, iteratee)
Parameters: This method accepts two parameters as mentioned above and described below:
- arrays: This parameter holds the arrays to inspect.
- iteratee: This parameter holds the iteratee invoked per element and is invoked with one argument (value).
Return Value: This method returns the new array of filtered values.
Example 1: Here, const _ = require(‘lodash’) is used to import the lodash library in the file.
javascript
| // Requiring the lodash library  const _ = require("lodash");       Â// Original array  varx = _.xorBy([3.1, 1.3, 4.6],          [3.3, 3.4], Math.floor); vary = _.xorBy([4.1, 2.3, 7.6],          [4.3, 7.4], Math.floor);  Â// Use of _.xorBy() method let gfg = _.xorBy(x); let gfg2 = _.xorBy(y);      Â// Printing the output  console.log(gfg); console.log(gfg2);  | 
Output:
[ 1.3, 4.6 ] [ 2.3 ]
Example 2:
javascript
| // Requiring the lodash library  const _ = require("lodash");        Â// Original array    Âvarx = _.xorBy([{ 'x': 11 }],        [{ 'x': 12 }, { 'x': 11 }], 'x');   Âvary = _.xorBy([{ 'x': 11.2 }],        [{ 'x': 12.2 }, { 'x': 56.3 },        { 'x': 38.21 }, { 'x': 11.2 }], 'x');   Â// Use of _.xorBy() method // The `_.property` iteratee shorthand   Âlet gfg = _.xorBy(x); let gfg3 = _.xorBy(y);       Â// Printing the output  console.log(gfg); console.log(gfg3);  | 
Output:
[ { x: 12 } ]
[ { x: 12.2 }, { x: 56.3 }, { x: 38.21 }]
Example 3:
javascript
| // Requiring the lodash library  const _ = require("lodash");       Â// Original array   Âvarx = _.xorBy([ 'p'], ['q',              'r', 's', 'p']);  Âvary = _.xorBy([ 'tee'], ['tee',      'cee', 'dee', 'bee', 'eee']);  Â// Use of _.xorBy() method // The `_.property` iteratee shorthand  Âlet gfg = _.xorBy(x); let gfg3 = _.xorBy(y);  Â// Printing the output  console.log(gfg); console.log(gfg3);  | 
Output:
['q', 'r', 's' ] ['cee', 'dee', 'bee', 'eee' ]
Note: This code will not work in normal JavaScript because it requires the library lodash to be installed.
Whether you’re preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, zambiatek Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we’ve already empowered, and we’re here to do the same for you. Don’t miss out – check it out now!
 
				 
					


