I have some html tags and I am trying to join them using javascript array.
I have tried printing out the array to see what it looks like. If it try printing out one array item, it works but the whole array doesn't show
<p>Click the button to join the array elements into a string.</p>
<button onclick="myFunction()">Try it</button>
<p class="demo">Banana</p>
<p class="demo">Orange</p>
<p class="demo">Appl</p>
<p id="demo"></p>
<script>
function myFunction() {
var fruits = document.querySelectorAll(".demo")[];
var y = document.getElementById("demo");
y.innerHTML = fruits.join(',');
}
</script>
I expect it to join the classname array together and print out a result but it shows nothing. I am not so good at javascript and would appreciate the help.
var fruits = document.querySelectorAll(".demo")[];- what do you expect this to do? I don't recognise the syntax, and it seems to give me a syntax error when I try a similar construct in the console.