I have paragraph and some of the words are displayed using <strong>
tag.
For instance, this text include <strong>MyWord</strong>
which I intend to use for learning vocabulary. There’s also <strong>another word</strong>
highlighted. This paragraph consists of tens of strong words.
I am aiming to obtain an HTMLCollection of unique strong words.
Initially when I use getElementsByTagName("strong").length
, It contains duplicate strong words and the actualy length of unique words is not correct.
How can I remove HTMLCollections or uniquely identify collection of strong words?
4
Answers
Here’s an approach
Here is an example:
After you get the list of words (by getting the texts from the
<strong>
elements), you can remove duplicates by running it through a Set constructor:The easiest way would be to use a Set like this: