0

I have two arrays below,

let array_one = [1, 2, 3, 4, 5]; //first array
let array_two = [5, 6, 7, 8, 9]; //second array

//I need [1, 2, 3, 4, 5, 6, 7, 8, 9]

In array_one and array_two has one common element that is 5 but I need this 5 only one time. I don't need to remove the duplicate elements but need one single element.

Dave Newton
  • 158,873
  • 26
  • 254
  • 302
Tahazzot
  • 1,224
  • 6
  • 27

1 Answers1

0

Please try this, It should work for you

    function onlyUnique(value, index, self) { 
        return self.indexOf(value) === index;
    }

    let arr = [...array_one,...array_two];

arr.filter(onlyUnique);
Harmandeep Singh Kalsi
  • 3,315
  • 2
  • 14
  • 26