0

I have data like this:

var data1 = ["RFCC","HCC","RFCC"];
var data2 = ["RFCC"];

I want to remove all duplicates from array above, the output should be like this:

var result = ["RFCC","HCC"];

If possible, how I could do the following task? Maybe someone could help me? Thanks in advance.

Abana Clara
  • 4,602
  • 3
  • 18
  • 31

1 Answers1

1

You can first concatenate the arrays into a single array. Then use filter() by passing the current item, index and the array itself to check whether the indexOf of the current item is the current index or not.

Try the following way:

var data1 = ["RFCC","HCC","RFCC"];
var data2 = ["RFCC"];
var res = data1.concat(data2);
res = res.filter((value, idx, self) => {
    return self.indexOf(value) === idx;
});
console.log(res);
Mamun
  • 66,969
  • 9
  • 47
  • 59