how to know if a variable is an array or object
Options
![Lukasz Kwiatkowski](https://us.v-cdn.net/6037124/user_avatars/2118965.jpg)
Lukasz Kwiatkowski
Member ✭
external API returns array for multiple items or object (without [ ] ) for single item depending on the number of items in the result (it is a bit weird but I have to integrate with this). Now when I pass to FE, it wants array otherwise does not work. I need to find a way to push result to array if only 1 item return or pass directly if list is returned otherwise it does not work... I was trying to build a conditional logic but count does not really work as it counts list items or simple object parameters so if count >1 wont work... Also try merging to an array and array and adding an element to an array but both wont solve as an array merged with object becomes an object... Any other ideas how to solve it? I am sure has the answer
Comments
-
hmmmm - sounds like you found an issue. Count works on the object because it considers it an associative array.
Feels like there are tweaks we should make to the filters
• is_array
• is_object
• safe_array
safe_array will make it so whatever you pass to it will either use itself (if its an array) or turn it into an array of 1 of it isn't an array.
We'll be able to get these into the next release - should be friday or monday. -
great looking forward to this!
thanks -
is there any update on this?
-
Yes. It will be Monday. It is on our dev environment - just testing some other items.
-
this is now live - new filters - safe_array, is_array, is_object, is_int, is_decimal, is_text, is_bool
safe_array should be what you want so its always an array -
hi you guys are awesome, thanks for so much for adding it!
I will probably be able to achieve what I want with "is_array"+ conditional however safe_array is not working with objects which was the main issue for me. is it a bug or this function always behaves that way? you can only safe array e.g. [1,2,3] or 1 but you cannot safe_array {a: 1,b: 2} - xano does not throw any errors however the statement would stay as {a: 1,b: 2} instead of [{a: 1,b: 2}] -
Strange. Will double check. We are doing another build today so we can fix this if needed.
-
i built a workout with "is_array" so not urgent but if you guys can fix "safe_array" I would welcome it happily as this is super neat
-
this is fixed
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