Adding an element to an array: Push and Append replacing the array, rather than adding on to it
Options
Marianna Kerppola
Member ✭
Hi! I've created a Function with a For Loop, where at the end of the loop, a new variable is created, and I want to add this variable to an array. I've tried both Push and Append. However, with each one, the entire array is replaced with the new variable as an element, rather than the new variable added on to the end of the array. Here's a video showing my set up and the results: https://www.loom.com/share/7dbd4aa6f2864916a809b30eee48946c
I didn't show it in the video, but I also tried Merge, which ended up with the same result as Push and Append shown above. Thanks for your help!
I didn't show it in the video, but I also tried Merge, which ended up with the same result as Push and Append shown above. Thanks for your help!
Comments
-
I would use the Array Function, Array: Add to End of Array (or also Add to Beginning of Array - depending on preference)
-
(Function Stack > Data Manipulation > Arrays)
-
Thanks ! I tried both Add to End and Add to Beginning of Array, but ended up with the same results as last time, where rather than adding the new item on, it replaced it altogether. Here's a Loom video showing the results with Add to End of Array: https://www.loom.com/share/6eacfb05bb144a0e918398d4f0501bfd
Anything else you would recommend? Thanks for your advice! -
Okay I'm pretty sure I've identified the issue... and it gets confusing with all the conditional statements and nested functions. But the array you are trying to update is actually being established inside the For Each Loop which is why you are only getting the final iteration. You will need to establish that array of user.trimester outside of the array and then you can add each iteration of the new value to that array... I see there are times that this array is established outside but due to the conditional logic, it seems when it's running through this the array is being established inside the for each loop - not outside.
Let me know if that makes sense or not -
Makes perfect sense ! I created separate array outside of the loop, and it worked as expected. Thanks for your help!
-
I'm having the same result. I tried with push and append, and confirmed my creation of the array is outside of the loop, but the array is simply replaced by the new value rather than appended.
-
Based on Michael's first suggestion, I created a new function, starting with the function stack "Array Function, Array: Add to End of Array (or also Add to Beginning of Array ". This worked as expected, but based on my testing, starting with "Update Variable" and then using the "append" or "push" function within "update variable" function, simply replaced the array with the new value. May be something to address if you can reproduce. This post was helpful in highlighting I should try another way, so gracias.
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