I have a table with hidden inputs. Iterating over them and concatenating into a string yields “[object HTMLElement]”. How can I properly extract their actual values?
const secretElements = document.querySelectorAll('input[type="hidden"]');
let combinedText = '';
secretElements.forEach(element => {
if (element.closest('tbody')) {
combinedText += element.value;
}
});
hey, looks like somewhere you’re adding an element itself not its .value; make sure you’re concatenating element.value. sometimes a stray selector or a misplacement in the DOM could cause this, so review your targeting. also try String(element.value) to force a conversion if needed.
In my experience, this behavior typically indicates that the code is unintentionally concatenating the entire element object rather than its value property. I encountered a similar issue where the glitch was due to an oversight in how the elements were being referenced. I resolved it by carefully verifying that the code exclusively accessed the value attribute. It also helped to inspect the DOM to ensure that the hidden inputs were correctly placed. Double-checking the selectors and confirming that no extraneous HTML elements were introduced into the concatenation process proved essential.