Returning [object Promise] instead of actual value

stsitilegnikcuferasyuguoy

I am new to promises as I am trying to get some objects to show there actual values on a webpage. Instead I am just getting a bunch of [object Promise] instead

This is the code I have so far:

\\**This section fetches the api results and puts them into a list/array**
async function getitglinkquerry(){
    
    var linkresults = await parseitgsearchqurry();
    console.log(linkresults);
    // var linkresultvalues = [];
    for (let i = 0; i < linkresults.length; i++) {
    var linkresultvalues = fetch(linkresults[i], {
        method: "GET",
        withCredentials: true,
        headers: {
            // needed to base64 encode my key with ":x" at the end of the api key then I used that for the authorization header.
        "x-api-key": "INSERTAPITHINGYHERE"}})
        .then(response => response.json())
        
        }
    return linkresultvalues;
}

\\**This section is trying to get the promise and parse the results**
async function parseitglinkquerry() {
    var querriedresults = await getitglinkquerry();
    console.log(typeof querriedresults);
    // linkresultvalues.push(response);
    const output = document.querySelector('span.ms-font-mitglue');
    let pre = document.createElement('p');
    
    pre.innerHTML = querriedresults;
    pre.style.cssText += 'font-size:24px;font-weight:bold;';

    output.appendChild(pre);
    
}
parseitglinkquerry();
}

What I tried

I tried reading the firefox promise.resolve method as that seems like what I was looking for: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve However I tried using the static promise.resolve method example they have and it didn't work for me. Like so:

\\**This section is trying to get the promise and parse the results**
async function parseitglinkquerry() {
    var querriedresults = await Promise.resolve(getitglinkquerry());
    console.log(querriedresults);  \\**This is where my promises are coming out of**
}

So I don't think that is what I am looking for. I also tried reading here: https://stackoverflow.com/a/64165144 but I don't know how to use the .then method to get the variables from the result. I already put .then in the api request at the first function yet I still have a list of promises.

Picture of the code: enter image description here

Picture of the result: enter image description here

I tried Promise.all() but it errored out and didn't work so I don't think that is the issue as well. I double checked my querriedresults variable to make sure its an object by using console.log(typeof querriedresults) and it said it was an object.

Attempted code:

async function parseitglinkquerry() {
    var querriedresults = await Promise.all(getitglinkquerry());
}

Error: Uncaught (in promise) TypeError: object is not iterable (cannot read property Symbol(Symbol.iterator))

Picture of the failure again

enter image description here

I tried using:

querriedresults.then(function(result){
        console.log(result)
        
    })

based on the information from here: https://stackoverflow.com/a/29516570/16660683 but that didn't work either as it gave me an error: Uncaught (in promise) TypeError: querriedresults.then is not a function

Bergi

The proper usage of Promise.all is

async function getItglinkQuery() {
    const linkresultUrls = await parseItgsearchQuery();
    const linkresultPromises = [];
    for (let i = 0; i < linkresults.length; i++) {
        const promise = fetch(linkresults[i], {
            method: "GET",
            withCredentials: true,
            headers: {
               "x-api-key": "INSERTAPITHINGYHERE"
            }
        })
        .then(response => response.json());
        
        linkresultPromises.push(promise);
//      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    }
    return Promise.all(linkresultPromises);
//         ^^^^^^^^^^^
}

Now, getItglinkQuery returns a promise for an array of values, not a promise for an array of promises.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Promise object not returning a value

Promise returning a function instead of an object

Why is result returning hex instead of actual value?

Mysql Coalesce returning 0 instead of actual value

returning ZoneAwarePromise instead of the actual value in Angular, why?

Why is this promise returning an [object Promise] and not the value?

Angularjs $resource save action return promise object instead actual value of response

Protractor Returning Promise Instead of Attribute Value

Async function returning promise, instead of value

JSON_VALUE value returning NULL instead of actual value

Returning a value from a Promise: [Object Object]

.str.contains returning actual found value instead of True or False

hincrby and hget returning True instead of actual value in Redis (python)

How to fix Text returning instance of " " instead of the actual value?

Returning the value of a +/- operator as a prefix with no actual value to add or subtract on a class object?

Axios API call returning Promise object instead of result?

Why is my asynchronous function returning Promise { <pending> } instead of a value?

Why is my asynchronous function returning Promise { <pending> } instead of a value?

vue-cookies get value return Object instead of actual value

JSON.parse returning [Object Object] instead of value

DataSnapShot Object's value returning 0 instead of a real value

How to print out actual object value instead of memory address in gdb?

How to return object instead of actual value on ajax call?

Axios returning a promise object

Returning a value from a Promise

Returning value of a promise in mongoose

Promise not returning value of request

Returning a value from the then() of a promise?

promise not returning value in order