I'm trying to take an array of names and add them to a single variable using a for loop then display it to the console.
var list = "";
var names = document.getElementsByTagName('h3');
for(i=0;i<names.length;i++){
list = list.concat(names[i].firstChild);
}
console.log(list);
But it outputs a long list of:
[object Text][object Text][object Text][object Text][object Text][object Text][object Text]
Note:
console.log(names[22].firstChild) outputs "Richard" in the console just fine. I'm just having problems concatenating them to the variable list.
The code of the is as follows.
<h3 style="color:white; font-weight:300;" class="staff">
Richard Smith<br>
<span style="font-size:14px;">Data Analyst</span>
</h3>
That is why I used .firstChild. If I use .innerText it returns both the name and the <span> that follows it.
firstChildbutinnerTextlistis a string