How to Join Two Lists

We had a question from a user who wanted to concatenate (join) two lists in their app.

Seemed like a pretty reasonable question, but it took me a minute to figure out the answer so I’m reposting my response here for the benefit of the whole community.

Question

I have two lists; listA which contains 1,2,3 and listB which has 4,5,6.
How to I join these two into a single list of 1,2,3,4,5,6?

Create 3 Varaibles

The first two are for the input lists, listA and listB and the third is an empty variable that we’re going to use to join the two lists together.

Technically, this third variable isn’t needed, but it makes the next set of blocks cleaner and easier to understand.


List to Text to List

First we convert the two lists to text.

Then the text is converted back into a list so that it can be displayed in the ListViewer.

Alternative

As mentioned above, the textItems variable isn’t strictly speaking necessary.

An alternative approach would be to use a for loop and individually add each item from list2 into list1 with the following blocks!

Remix

Here’s the link so you can try this for yourself.

https://x.thunkable.com/copy/7763cee8d0d73eac0fdc1663601431a9

Open Questions

Do you have any other ways of doing this? or a preferred way of doing this?

How do these approaches fare a the input lists get longer and longer? Which approach gives the fastest concatenation?

7 Likes