For AI agents: the complete documentation index is available at /llms.txt, the full documentation bundle is available at /llms-full.txt, and this page is available as Markdown at /reference/array/xor.md.

xor es-toolkit

Creates a new array with elements that exist in only one of two arrays.

const result = xor(arr1, arr2);

Usage

xor(arr1, arr2)

Use xor when you want to find the symmetric difference of two arrays. It returns a new array consisting of elements that exist in only one of the two arrays and not in their intersection.

import { xor } from 'es-toolkit/array';

// Get the symmetric difference of number arrays.
xor([1, 2, 3, 4], [3, 4, 5, 6]);
// Returns: [1, 2, 5, 6]

// Get the symmetric difference of string arrays.
xor(['a', 'b'], ['b', 'c']);
// Returns: ['a', 'c']

Duplicate elements are automatically removed.

import { xor } from 'es-toolkit/array';

xor([1, 2, 2, 3], [3, 4, 4, 5]);
// Returns: [1, 2, 4, 5]

Parameters

arr1readonly T[]required

The first array to compare.

arr2readonly T[]required

The second array to compare.

Returns

Returns a new array representing the symmetric difference of the two arrays.

T[]
Source: es-toolkit

Re-exported verbatim from es-toolkit. Implementation, edge cases, and performance behavior are owned upstream. This page mirrors the documentation at the pinned version; the linked source is authoritative.