You could save yourself some time and effort with the very useful utility library Lodash.
The function you're looking for is Union
As stated by Lodash:
Creates an array of unique values, in order, from all given arrays
using SameValueZero for equality comparisons.
Example
_.union([2], [1, 2]);
// => [2, 1]