Get all Input tags and add a value

How do i get all of the Input tags and add a value to them?

var inputs = document.getElementsByTagName('input')

For example, i want to add the text “hello”. If there were 2 input tags, and the first one had the value set to test and the second one blank, i would want the first input be testhello and the other hello

Untested code ahead!

let str = "hello";
document.querySelectorAll('input').forEach(input => {
  input.value += str
1 Like