VOOZH about

URL: https://www.geeksforgeeks.org/javascript/lodash-_-xor-method/

⇱ Lodash _.xor() Method - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

Lodash _.xor() Method

Last Updated : 2 Sep, 2024

Lodash _.xor() method returns an array of the symmetric difference of given arrays i.e. it will create an array that contains an element that doesn't exist in any other array.

Syntax:

_.xor(arrays);

Parameters:

  • arrays: This parameter holds one or more arrays that need to be inspected.

Return Value:

  • It returns an array of symmetric differences of given arrays.

Example 1: In this example, we are printing the xor of two arrays having values as integers by the use of the _.xor() method.

Output:

[ 3, 2 ]

Example 2: In this example, we are printing the xor of three arrays having values as integers by the use of the _.xor() method.

Output:

[ 2, 500 ]

Example 3: In this example, we are printing the xor of two arrays having values as strings by the use of the _.xor() method.

Output:

[ 'machine-learning', 'system-app' ]

Note: This will not work in normal JavaScript because it requires the library lodash to be installed.

Comment