I have the following code and it executes perfectly.
var website = "youtube.com"
const getViews = (website) => {
fetch("/api?Action=TrafficHistory&Range=1&Output=json&ResponseGroup=History&Url=" + website, {
headers: {
"X-Api-Key": "hidden"
}
})
.then((res) => res.json())
.then((data) => JSON.stringify(data))
.then((data) =>{
let parsedData = JSON.parse(data)
console.log(parsedData)
})
}
getViews(website)
Instead of console logging the data I wanted to return the variable parsedData that holds the data. I tried modifying the like so but it gives me a value of undefined.
var website = "youtube.com"
const getViews = (website) => {
fetch("/api?Action=TrafficHistory&Range=1&Output=json&ResponseGroup=History&Url=" + website, {
headers: {
"X-Api-Key": "hidden"
}
})
.then((res) => res.json())
.then((data) => JSON.stringify(data))
.then((data) =>{
let parsedData = JSON.parse(data)
return parsedData
})
}
let holdData = getViews(website)
console.log(holdData)
What can I do to fix this?