You’d get the spans and map back the text content
var text = [].map.call(document.querySelectorAll('.topics span'), function(elem) {
return elem.textContent; // or elem.dataset.value for the data-attribute
});
console.log(text)
<div class="topics">
<span class="topic" data-value="hello">hello</span>
<span class="topic" data-value="world">world</span>
<span class="topic" data-value="one">one</span>
<span class="topic" data-value="two">two</span>
<span class="topic" data-value="six">six</span>
</div>
2
solved How to combine values in the array? [closed]