How to combine two objects into a single array
Hey there! In this guide, we'll explore how to return a list of mixed objects from different tables using Xano. This can be incredibly useful when you need to combine data from multiple sources into a single response.
Step 1: Create Your Data Models
First things first, you'll need to set up your data models in Xano. For this example, let's assume we have two tables: Info and User.
Step 2: Get Records from Different Tables
To retrieve data from multiple tables, we'll use the get record operation. Here's how you can do it:
- Drag and drop the
get recordoperation onto the canvas. - In the configuration panel, select the
Infotable from the "Table" dropdown. - Repeat step 1, but this time select the
Usertable.
You should now have two separate get record operations, one for each table.
Step 3: Combine the Results
Now that we have the data from both tables, it's time to combine them into a single array. Follow these steps:
- Create a new variable called
combinedResultand set its type toarray. - Drag and drop the
pushoperation onto the canvas. - In the
pushoperation's configuration panel, select thecombinedResultvariable from the "Array" dropdown. - For the "Value" field, connect the output of the first
get recordoperation (e.g.,info1). - Repeat steps 2-4, but this time connect the output of the second
get recordoperation (e.g.,user1) to the "Value" field.
Your canvas should now have a combinedResult array containing objects from both the Info and User tables.
Step 4: Return the Combined Result
Finally, we need to return the combinedResult array as the operation's output:
- Drag and drop the
returnoperation onto the canvas. - In the configuration panel, connect the
combinedResultvariable to the "Value" field.
And that's it! When you run this operation, Xano will return a list containing objects from both the Info and User tables, seamlessly combined into a single response.
By following these steps, you can easily create mixed lists of objects from different tables, enabling you to build more powerful and flexible applications with Xano.
Sign up for Xano
Join 100,000+ people already building with Xano.
Start today and scale to millions.
Start building for free

