I have a for of
statement in JS that returns HTML element ids but they are in multiple outputs. I would like to take these outputs and put them in an array.
For example the HTML is:
<div>
<button id="savebtn-1"></button>
</div>
<div>
<button id="savebtn-2"></button>
</div>
and my JS is:
const elements = document.querySelectorAll("button");
for (const element of elements) {
let id = elements.getAttribute("id");
}
console.log(id)
will show:
savebtn-1
savebtn-2
How can I get these outputs into an array?
Thanks for any attention you may give this question.