Skip to main content
All CollectionsBubble FeaturesQuick Tips
How to Use the First Item Operator
How to Use the First Item Operator
Updated over a week ago

Transcript

In this Quick Tip, we're going to learn about the first item list operator. While working on your app, you'll be frequently retrieving a single thing from a list of things. Most commonly, we return a list of things when we use the Do a search for data source.

For example, here we have a repeating group that is doing a Search for Users and displaying each user's email. But if we only wanted to retrieve one specific thing from this list, instead of doing a search, we would have to use the first item operator to build that expression.

To demonstrate this, let's add Dynamic Data to a text element with the goal of showing the first item from our repeating group of user emails. When we do the search we'll get an error, as we're returning a list of users and not text. But when we click More, we find the list operators we can work with.

For this, we'll click first item. Now this expression will Search for Users and display only the first item that was entered into the database that matches the search and the search's constraints, if there are any.

But because we're using a text element, we need a text value for this expression and, just like our repeating group of users emails, we will get the user's email like so. Now our expression reads Do a Search for Users: first item's email.

When we preview the page, we can see the user's email of the user that meets this criteria. First item returns the first item of the list, so in this case the first item to be entered into our user database was this user so that's what we returned.

The principle of getting the first item from a list is really important. Often times we want to modify a Thing, but we don't actually have that Thing at our disposal, we only have the ability to do a constrained search. But if we know where that Thing is in the list, we can use a list operator like first item to our advantage.

That's it for this Quick Tip! For more, be sure to check out bubble.io/academy.


Did this answer your question?