I create a function which saves in a variable text
the content of my clipboard.
I want to return the function output to another variable called my_text
, however I am not able to do so.
I have to do that since I want to apply some NLP algorithm to my_text
I get my_text is undefined
function paste() {
navigator.clipboard.readText()
.then(text => {
console.log(text);
return text
})
.catch(err => {
console.error("Failed to read clipboard contents: ", err);
});
}
var my_text = paste()`
I think it is because my function paste()
is async, but I am still not sure how to assign what it returns to a variable.