How should I combine array values?
![pete letkeman](https://us.v-cdn.net/6037124/user_avatars/5524134.jpg)
I have the following:
I want to replace userId:[3,14,2] with userIds: '3,14,2'.
Essentially I want to do a JOIN on the array.
I could have maybe 100 different JSON objects with arrays containing maybe 100 elements.
I can loop through all of the JSON objects in the result and then loop through all userIds appending them to a string variable. That is easy enough, but is that the best way to do this?
Could this be done with Lambdas? If so please provide some examples.
I would like to do the same with securityGroupId and securableEntityId.
Best Answers
-
@Michael Udinski, sorry not exactly what I'm asking, let me try again.
I have 100 records, each with an array that can have up to 100 values.
I am NOT updating the database.
I want to take each array and do an array.join (https://www.w3schools.com/jsref/jsref_join.asp) so that instead of an array of 100 values I have a single string with all of the values commas separated, and I want to keep the other values or the record as is.
I CAN do this easily enough in Xano with a variable and a couple of loops.
---------------
string temp = ''
select fld1, fld2, fld3 from table1 as results
for each record in results
for each value in record[fld1]
temp = temp + ',' + value
next
record.flat = temp
temp = ''
next
----------------------
Is this the best and/or only way to do this with Xano?
However, I want to do:
select GROUP_CONCAT(fld1) as flat, fld2, fld3 from table1 as results
But, if I can't use group_concat or something like that then can I do something with a Lambda expression to get the result that I want?
-
Most db-level functions aren't available in-query, but you can do them in the function stack. Xano supports a join filter (documented here https://docs.xano.com/working-with-data/data-type-filters/array-filter) that concatenates your array into a string without the inner loop- should be much faster.
We discuss these kinds of data manipulation questions on our State Change Pro office hours on a daily basis. Our next is tomorrow!
Answers
-
@pete letkeman if you want to replace something with another value then you can use Update Variable. If you are wishing to combine two arrays then I would use the Merge filter or function Array: Merge.
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