Я не могу понять, как обновить таблицу из переменной JSON с помощью цикла 'for..of'.
Используется async / await, но без помощи!
for (const item of file) { //if I remove for loop and use only a single instance 'eg. file[4]' code works correctly.
table(item)
console.log(5)
}
async function table(item){ //file holds "data.json"--> {Index,Roll,Name}
var x=item
var a=x.Index;
var b=x.Roll;
var c=x.Name;
console.log("connected"+a+b+c)
await sql(a,b,c).then(console.log("After await"))
}
console.log("done");
}
async function sql(a,b,c){console.log("got in async");
return new Promise ((resolve, reject) => {resolve(
con.query('insert into CS(s,roll,name) values(?,?,?)',[a,b,c],function (err, result){
if (err) throw err;
}))
})
}
ВЫХОД
connected11111abhilashabhilash
got in async
[nodemon] restarting due to changes...
After await
5
connected21112anuraganurag
got in async
After await
5
connected31113abhinavabhinav
got in async
After await
5
connected41114joshjosh
got in async
After await
5
connected51115caustavcaustav
got in async
After await
5
connected61116deepanshudeepanshu
got in async
After await
5
connected71117eraera
got in async
After await
5
connected81118ekanshekansh
got in async
After await
5
connected91119faranfaran
got in async
After await
5
connected101120faisalfaisal
got in async
After await
5
connected111121gauravgaurav
got in async
After await
5
connected121122mananmanan
got in async
After await
5
connected131123nileshnilesh
got in async
After await
5
done
done
done
done
done
done
done
done
done
done
done
done
done