In my current project, I am facing an issue with storing tweet IDs for later use. Here is the code snippet I am using:
let twit = require('twit');
let config = require('./config.js');
const T = new twit(config);
let retweetIDs = [];
const promise = T.get('statuses/user_timeline', {screen_name: 'someusername', count: '1'});
promise.then(res =>{
let id = res["data"][0]["id"];
retweetIDs.push(id)
});
console.log(retweetIDs)
When I check the console.log(), it returns an empty array []. It seems like a timing issue due to JavaScript being asynchronous, but I'm not sure how to solve it. Any advice or guidance on this problem would be greatly appreciated.