Javascript: How to send event after changing programmatically without JQuery

This snippet will change an input programmatically and then dispatch an input event which will tell the javascript code running on the page that the input has changed.

let myinput = document.querySelector("input#myinput");
// Set value
myinput.value = "newvalue";
// Simulate input event
myinput.dispatchEvent(new Event('input', {
    bubbles: true,
    cancelable: true,
}));