I am working on a function
String.prototype.isActualWord = function() {
if ($ != undefined) {
let str = this.toLowerCase()
let res = false
const url = "https://api.wordnik.com/v4/word.json/" + str + "/definitions?limit=200&includeRelated=false&useCanonical=false&includeTags=false&api_key=_THIS_IS_CONFIDENTIAL_";
try {
$.ajax({
type: "GET",
url: url,
async: false,
success: function (data) {
res = true
},
error: function (data) {
res = false
}
})
}
catch(e) {
throw new Error(e.message)
}
return res
} else {
throw new Error("Please Include jQuery In Your Project")
}
}
Here is the fetch code:
let res = false
fetch(url)
.then((response) => {
return response.json();
})
.then((data) => {
if(data[0] != undefined) {
res = true
}
});
you see, I want to remove the jQuery dependency from my project. how can I achieve this using the asynchronous way using fetch API. i have tried many ways but in vain.