0

Hello Stack Overflow :)

I have a problem about an object who is unavailable outside a for().

let result1 = {}; // declaration of the object
let key = "results";
result1[key] = [];

async function start(keyword, site) {

    const params = {
        api_key: "XXXXXXXXXXX",
        q: keyword,
        gl: "fr",
        hl: "fr",
        location: "France",
        google_domain: "google.fr",
        num: "100",
        include_answer_box: "false",
        include_advertiser_info: "false"
    }

    axios.get('https://api.valueserp.com/search', { params })
        .then(response => {
            var result = response.data.organic_results;
            for (var i = 0; i < 100; i++) {
                if (result[i].link.includes(site)) {
                    result1["results"].push({ motcle: keyword, position: (i + 1), url: result[i].link }); // this object is the problem
                }
            }
            return JSON.stringify(result1); // it doesn't return anything :(
        }).catch(error => {
            return error;
        })
}

You will save my life if you help me to resolve this problem :D

See you soon !

  • "it doesn't return anything :(" — It does, but nothing ever inspects the return value of **that** callback function – Quentin Dec 20 '21 at 12:14
  • NB: Using the `async` keyword is pointless until you also use the `await` keyword – Quentin Dec 20 '21 at 12:14

0 Answers0