Set a value in a list of objects if condition is met
I have a list of objects made like this:
[{restaurant_id: 2, entrance: 4}, {restaurant_id:3, entrance:5},{restaurant_id:4, entrance:6}..]
My goal is to edit (possibily using a conditional set filter, the list if restaurant_id equals a given number.
I know this could be done also through a FOR cicle or in other ways but I'm looking at the fastest way to do this.
Would be achievable through a filter?
Answers
-
Federico,
In my opinion, unless you have a few hundred thousand objects to sort through in your list, I think your best option would be to use a for loop because they are still exceptionally quick. I would loop through each object, compare the restaurant_id, and then alter your chosen value if the ID matches.
If you want to continue searching for filtering options, I would recommend searching Xano Conditional Set Filters.
Let me know if you run into any more issues.
-Evan
-
Hi @Federico Somaschini, @evanwaller has the right idea. There are some tricks in Xano that you can use instead of a For Each Loop like the Array functions. In this case, you can use Array:Find First Element Index where restaurant_id = 6 and using that index, you can update the existing object array at that position. Here's a video on it:
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