- Create an empty array that would store the unique elements from the two arrays.
- Iterate over all elements of array1 using a loop.
- Set the initial flag value as 0 for each iteration.
- In that loop Iterate over all elements of array2 using another loop and check if array1[element] is present in array2.
- If present, remove the element from array2 using splice() method and set the flag to 1.
- If array2 has been fully traversed for array1[element] and the flag is still equal to 0, add the array1[element] to the unique elements array.
- Repeat steps 4-6 for each element in array1.
- Finally, push array2 to the unique elements array since all duplicate elements have been removed from array2 (refer Step 5).
Example: The implementation of the above approach is given below: