0

I have an HTML document as follows.

<div data-map_id="0"></div>
<div data-map_id="0"></div>
<div data-map_id="1"></div>
<div data-map_id="1"></div>
<div data-map_id="0"></div>
<div data-map_id="0"></div>
<div data-map_id="2"></div>
<div data-map_id="2"></div>

I could get an array as follows.

map_id_array=["0", "0", "1", "1", "0", "0", "2", "2"];

But I want to get an array as follows from this array or from HTML directly.

map_id_array=["0", "1", "2"];

How to do this in pure JavaScript?

webelf000
  • 147
  • 9
  • Please the existed [answer](https://stackoverflow.com/questions/1960473/get-all-unique-values-in-a-javascript-array-remove-duplicates) how to filter duplicates with pure Javascript. – Alla Danchenko May 13 '20 at 18:37

1 Answers1

1

While parsing you can make use of Sets in javascript. It will ensure values are entered only once

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Set

Deepak Uniyal
  • 323
  • 1
  • 4