At the page I have these sections:
<section id="questions-688">
</section>
<section id="test">
</section>
<section id="stats-688">
</section>
<section id="answers-636">
</section>
<section id="someDiv">
</section>
I would like to create an array with these numbers: [688, 636]. So when id of section is started with questions or answers or stats, I want to add number belongs to this ID to array, but ONLY ONCE. How can I do this via javascript?
Here is function which create an array [688, 688, 636], but I need [688, 636].
var selector = 'section[id^=stats-],section[id^=answers-],section[id^=questions-]';
segments = Array.prototype.map.call(document.querySelectorAll(selector), function (section) {
return section.id.split('-')[1]|0;
});
How can I do this?