Welcome to this tutorial on working with arrays in Xano, a no-code platform for building and deploying backend services. In this guide, we'll cover how to update records with arrays of items, query for specific values within arrays, and perform data transformations using forEach loops and the powerful Zetta Transform feature.
Let's start by exploring how to update a record with an array of values in your database. Suppose you have a table schema with an `array_texts` column (an array of single values) and an `array_objects` column (an array of objects).
To add a new value to an existing array, follow these steps:
To add an array of values to an existing array, follow these steps:
To add a new object to an array of objects, follow these steps:
Xano provides powerful querying capabilities to filter and retrieve specific values from arrays. Let's explore two methods: `findFirstElement` and `findAllElements`.
The `findFirstElement` function searches through an array and returns the first element that matches the specified condition. The condition is defined using a custom query syntax similar to a database query.
In this example, `$` represents each item in the array, and you can access its properties using dot notation (e.g., `$.field`). The condition checks if the `field` property of the item equals the specified `'value'`.
The `findAllElements` function works similarly to `findFirstElement`, but it returns an array containing all elements that match the specified condition.
This function allows you to retrieve multiple matching items from the array.
Xano provides two methods for transforming data within arrays: `forEach` loops and the powerful Zetta Transform feature.
The `forEach` loop iterates over each element in an array and allows you to perform transformations on the data. Here's an example:
This approach ensures that the original data remains untouched while creating a new array with the transformed values.
Zetta Transform is a powerful feature in Xano that allows you to perform data transformations more efficiently. It leverages a declarative syntax and optimized processing, making it faster and more readable than traditional loops.
The Zetta Transform syntax uses the `$$` symbol to represent the current value of the field, and the `|` (pipe) character to apply the specified transformation function.
For more information on the available Zetta Transform functions and their syntax, refer to the official Xano documentation or check out the tutorial videos on YouTube.
With these techniques for working with arrays in Xano, you can efficiently update records, query specific values, and transform data within your applications. If you have any questions or need further assistance, don't hesitate to reach out to the Xano community or contact the live support team within the platform.
Happy coding!
This transcript was AI generated to allow users to quickly answer technical questions about Xano.
I found it helpful
I need more support