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,824
  • 17
  • 99
  • 186
user2828442
  • 2,415
  • 7
  • 57
  • 105

1 Answers1

3

Use Set to remove duplicate values :

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

console.log(result);
gorak
  • 5,233
  • 1
  • 7
  • 19