I am struggling to find and replace array in following case.
I need to replace comments array of particular post_id (e.g. 89) from data
array with comments array of postDetails
and result should be data
array with replaced comments of that post_id.
"data": [
{
"post_id": "89",
"event_id": null,
"title": null,
"description": null,
"links": null,
"user_id": "28",
"user_name": "Namrata Tambare",
"user_profile_path": "profile-images/20220118060204-cartoon-dp-for-girls-whatsapp.jpg",
"mediaData": [
{
"id": 119,
"social_media_posts_id": 82,
"media_type": "image",
"images": "20220111070528-123.jpg",
"videos": null,
"file_path": "images/20220111070528-123.jpg"
},
{
"id": 120,
"social_media_posts_id": 82,
"media_type": "image",
"images": "20220111070528-320.png",
"videos": null,
"file_path": "images/20220111070528-320.png"
},
{
"id": 121,
"social_media_posts_id": 82,
"media_type": "video",
"images": null,
"videos": "20220111070528-pexels-c-technical-6153734.mp4",
"file_path": "videos/20220111070528-pexels-c-technical-6153734.mp4"
}
],
"likeCount": 1,
"alreadyLike": "yes",
"comments": [
{
"id": 90,
"post_id": 82,
"comment": "efretret",
"comment_by_user": 28,
"parent_id": 0,
"created_at": "2022-01-17T06:28:49.000000Z",
"post_comment_users": {
"id": 28,
"first_name": "Na",
"last_name": "Ta",
"profile": "20220118060204-cartoon-dp-for-girls-whatsapp.jpg",
"profile_path": "profile-images/20220118060204-cartoon-dp-for-girls-whatsapp.jpg"
},
"post_comment_replys": []
}
],
"event_total_going": "",
"event_total_not_going": "",
"event_total_maybe": "",
"event_start_date": null,
"event_location": null,
"event_status": null,
"post_created_at": "2022-01-11T07:05:28.000000Z"
},
{
...
},
{
...
},
{
...
}
]
"postDetails": [
{
"id": 89,
"user_id": 30,
"user_name": "new nmt testing test 123",
"user_profile": "20211025055017-ima5.png",
"user_profile_path": "profile-images/20211025055017-ima5.png",
"horse_id": null,
"horse_name": "",
"horse_profile": "",
"horse_profile_path": "",
"description": "test post",
"links": null,
"created_at": "2021-10-25T05:51:21.000000Z",
"imagesVideos": [
{
"id": 72,
"social_media_posts_id": 46,
"media_type": "image",
"images": "20211025055121-2514219.jpg",
"videos": null,
"file_path": "images/20211025055121-2514219.jpg",
"created_at": "2021-10-25T05:51:21.000000Z"
},
{
"id": 73,
"social_media_posts_id": 46,
"media_type": "video",
"images": null,
"videos": "20211025055121-pexels-video-kickstarter-5299577.mp4",
"file_path": "videos/20211025055121-pexels-video-kickstarter-5299577.mp4",
"created_at": "2021-10-25T05:51:21.000000Z"
}
],
"totalLikes": 1,
"comments": [
{
"id": 27,
"post_id": 46,
"comment": "test comment",
"comment_by_user": 30,
"parent_id": 0,
"created_at": "2021-10-25T05:52:16.000000Z",
"post_comment_users": {
"id": 30,
"first_name": "new nmt testing",
"last_name": "test 123",
"profile": "20211025055017-ima5.png",
"profile_path": "profile-images/20211025055017-ima5.png"
},
"post_comment_replys": []
}
]
}
],
by using find
I can get object from data
array but how can I replace comment array of that with postDetails
and get whole updated data
array ?
Please guide and help.