I'm creating a search site for video content. In the results, I'd like to have a button that will copy to the clipboard the Video name and Video URL that I have in the database. I've found a JS function that will copy set text("Copied text" in the code below). I need the function to copy a variable(from an array), which will change, depending what someone is searching for.
<button onclick="myFunction()">Copy Video Name & URL</button>
function myFunction() {
var copyText = "Copied text";
let input = document.createElement('input');
input.setAttribute('type', 'text');
input.value = copyText;
document.body.appendChild(input);
input.select();
document.execCommand("copy");
document.body.removeChild(input)
}