You can find this answer in the Mozilla Developer Network or MDN on the clipboard API. It is very easy and straight forward to use and implement. However, I decided to write this short bit to mention something that got me in a loop of wonders and cost me time and delayed one of my hotfixes to a certain project.
In the code above you can test the clipboard API using Vanilla JavaScript. Moreover, you have options to disable the input field or make it read-only. When you test it you will notice that disabling the input interferes with the clipboard API and prevent it from getting the content of the input. I wasn't aware of that until I got stuck in the loop of wonders I mentioned before.