0

This is my array:

[ 
  'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
  'hBwNVTlluaagZ5Fqd6f0Ws3Vxtn1',
  'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
  'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3'
] 

If want to check, if it has similar objects then I want it to be merged into one and return me array as:

[
  'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
  'hBwNVTlluaagZ5Fqd6f0Ws3Vxtn1',
] 

How is this possible in JavaScript or TypeScript?

halfer
  • 19,471
  • 17
  • 87
  • 173
user2828442
  • 2,213
  • 5
  • 50
  • 87

1 Answers1

3

Use Set to remove duplicate values :

array = [ 'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
  'hBwNVTlluaagZ5Fqd6f0Ws3Vxtn1',
  'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3',
  'Ddy1QVOAO6SIvB8LfAE8Z0Adj4H3' ];
  
var result = [...new Set(array)];

console.log(result);
Rajan
  • 4,939
  • 1
  • 5
  • 17