I wonder if someone could help? I have data returning from a twitter API call and have split it into 2 arrays.
twitterGetTweets(twIds)
.then(response => {
let tweets = response.data;
let users = response.includes.users;
tweets.map(item => {
tweets.forEach(item => item._id = uuid.v4());
})
users.map(item => {
users.forEach(item1 => item._id = uuid.v4());
})
console.log(tweets);
console.log(users);
This comes from this original json return
“data”: [
{
“created_at”: “2022-07-20T15:03:58.000Z”,
“text”: “tweet 1 text”,
“id”: “1549772107999023104”,
“author_id”: “1127391888523300865”
},
{
“created_at”: “2022-07-20T19:04:53.000Z”,
“text”: “Tweet 2 text”,
“id”: “154983273…”,
“author_id”: “1127391888523300865”
},
{
“created_at”: “2022-07-20T21:30:15.000Z”,
“text”: “Tweet 3 text”,
“id”: “1549869318359449600”,
“author_id”: “1127391888523300865”
}
],
“includes”: {
“users”: [
{
“url”: “url details”,
“profile_image_url”: “https://pbs.tw…”,
“username”: “profile 1”,
“id”: “1127391888523300865”,
“name”: “username…”
}
]
}
}
In this example there is only one user returned, but this could be any number of users depending on the request sent to the API
What I need to do is combine the 2 arrays so that each of the tweet entries has the user data contained to produce
{
“created_at”: “2022-07-20T21:30:15.000Z”,
“text”: “Tweet 3 text”,
“id”: “1549869318359449600”,
“author_id”: “1127391888523300865”
“profile_image_url”: “https://pbs.tw…”,
“username”: “profile 1”,
“name”: “username…”
}
The filter point is the id field in the user and the author_id in the tweet. As the return of the user data is a variable depending on the request to the API. i.e. there could be 2 tweets from user 1 and 1 from user 2 etc. I am assuming there is some iteration on array to to push then into array 1, but sadly that’s beyond my current understanding on combining arrays.
Any help would be greatly appreciated.