Update an array within an object array
Options
![Chetan -2435942](https://us.v-cdn.net/6037124/user_avatars/2435942.jpg)
Chetan -2435942
Member ✭
Hello,
I have a "comments" object array within an object array of "Posts".
I want to selectively push this comments array into a fresh results object array that is similar to posts, but i am unable to traverse the results object array in the for loop.
Posts:
{
user
{
username: "ABC",
...,
}
Comments:
{
Comment id= 124,
Parent_id=0
}
}
I am basically looking to select all comments within each post to select and push all parent comments into a new results object
1. So created a for loop for each of the Posts as item
2. created results object variable and updated with everything else including a "comments" path for comments[] (blank array).
3. Then have a for loop for all comments in item as "commentitem"
3.a. Within this loop a if conditional to check if the loop has parentid = 0
Issue: now i need to push the identified commentitem into results object for that post, and i am unable to traverse to results.0.comments[] and results.1.comments[]
how do i assign or push commentitem[] into results.0 or results.0.comments[] and so on?
I am using a variable (i) to count the post items i have already gone through in loop 1 and tried using that in 3a e.g. results[i].comments - unfortunately this is not possible to be used.
I have a "comments" object array within an object array of "Posts".
I want to selectively push this comments array into a fresh results object array that is similar to posts, but i am unable to traverse the results object array in the for loop.
Posts:
{
user
{
username: "ABC",
...,
}
Comments:
{
Comment id= 124,
Parent_id=0
}
}
I am basically looking to select all comments within each post to select and push all parent comments into a new results object
1. So created a for loop for each of the Posts as item
2. created results object variable and updated with everything else including a "comments" path for comments[] (blank array).
3. Then have a for loop for all comments in item as "commentitem"
3.a. Within this loop a if conditional to check if the loop has parentid = 0
Issue: now i need to push the identified commentitem into results object for that post, and i am unable to traverse to results.0.comments[] and results.1.comments[]
how do i assign or push commentitem[] into results.0 or results.0.comments[] and so on?
I am using a variable (i) to count the post items i have already gone through in loop 1 and tried using that in 3a e.g. results[i].comments - unfortunately this is not possible to be used.
Comments
-
4.2.1.1 is where i am not able to push or append the array into the results array object.[Capture1.PNG]
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback