Ask coding questions

← Back to all posts
how to fix Only absolute URLs are supported??
NewCoder2976 (0)

const fetch = require('node-fetch');

const array = [10, 20, 30];
const chaydi = [
"https://kodaktor.ru/api/m/",
"https://kodaktor.ru/api/MS2/",
"https://kodaktor.ru/api/MS3/",
];
let data_result = '';
async function array_promises(array, chaydi) {
const headers = { "Content-Type": "application/json" };

for( let i of array){
let request = await fetch(chaydi[i] + array[i] + '/', {headers})
.then(data => data.json);
data_result.push(request.result);
}
return result;
};
result = array_promises(array, chaydi);
console.log(data_result);

Comments
hotnewtop
RayhanADev (1914)

Okay so you have several problems:

for( let i of array){

it doesn't work quite like that, try this:

for(i = array.length - 1; i > 0; i--) {

and then when you fetch, your api is not giving a json response. Change the .json() to .text() and see what it says. It's very weird so solve that and it should work :D!

NewCoder2976 (0)

@RayhanADev thanks for helping me. I'm trying to fix this.

RayhanADev (1914)

Well first off, I don't think its relevant to your current problem but line 15:

        .then(data => data.json);

should be:

        .then(data => data.json());

and then on line 9:

let data_result = '';

I assume you want to push to an array not string so it should be:

let data_result = [];

Give me a few and I'll figure out your problem too :)