I want to use the data I get from a fetch request so I return it as an array. The return value(array) will be use to another function but I get a promise :
Promise {<pending>}
__proto__: Promise
[[PromiseState]]: "fulfilled"
[[PromiseResult]]: Array(10)
Below is the complete code
function getEmailList() {
fetch(myData.root_url + '/wp-json/wp/v2/email', {
method: "GET",
headers: {
'Content-Type': 'application/json'
}
}).then(response => {
return response.json();
}).then(emails => {
emails.map((email) => {
emailArr.push(email.title.rendered)
})
return emailArr;
}).catch(err => console.log('failed', err))
}
function getData() {
let emailList = getEmailList();
console.log(emailList)
}