# How to set/access 2D list/array

**URL:** <https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562>\
**Category:** Questions about Thunkable X\
**Created:** [July 26, 2021, 9:10pm UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562 "2021-07-26T21:10:09Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![bnice](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/bnice/32/110648_2.png) [@bnice](https://community.thunkable.com/u/bnice)\
**Post date:** [July 26, 2021, 9:10pm UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/1 "2021-07-26T21:10:09Z")

</div>

Hey everyone,  
My inability to answer this question is probably a sign I have been coding too long today. Two-part question. How do you set the value to a 2D list after it has been initialized? And how do you access something from a list inside another list? It’s easy to do in a written language, but I’m struggling over here on how to put it in blocks.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [July 27, 2021, 5:08am UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/2 "2021-07-27T05:08:30Z")

</div>

What do you mean by “set the value to a 2D list”? You can only set list _item_ values. So are you asking how to add a list as a list item?

I have a feeling using JSON (and perhaps Firebase) is going to be easier than trying to use two-dimensional lists but I don’t have a ton of experience with them.

---

<div class="post-metadata">

**Author:** ![bnice](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/bnice/32/110648_2.png) [@bnice](https://community.thunkable.com/u/bnice)\
**Post date:** [July 27, 2021, 7:20am UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/3 "2021-07-27T07:20:07Z")

</div>

I know it sounds odd, but from a written programming perspective, it makes sense 😂. It does essentially make a table. The first list block is the rows, and the lists inside the list are the columns. Here is what I am trying to do (example), and my goal is to get the 5.

 ![Screenshot (16)](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/b/1/b105af25089b74669569169a326850281a73b04c.png)  
 ![List](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/d/8d9d461670a973929e0adb934bf77865e4ef5391.jpeg)

Now in a writing language like Java, I can do something like this to get the same result.:

```auto
int[][] Array = new int{{1,2,3}, {4,5,6}, {7,8,9}};

```

To get the array value, you can just grab the value.

```auto
int val = Array[2][2];

```

Or if it is an ArrayList, you use .get notation. So something like. (Syntax idea, not perfect):

```auto
int val = Array.get(2).get(2);

```

So I need to get the first value(row of list), and then get the value from the column (Inside list)

---

<div class="post-metadata">

**Author:** ![muneer](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/muneer/32/75210_2.png) [@muneer](https://community.thunkable.com/u/muneer)\
**Post date:** [July 27, 2021, 8:01am UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/4 "2021-07-27T08:01:21Z")

</div>

Check this  
[https://x.thunkable.com/projectPage/60ffb90e59eff60011a5a85b](https://x.thunkable.com/projectPage/60ffb90e59eff60011a5a85b)

I’m not sure if this is what you mean but if we start with something we can always develop it further.

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [July 27, 2021, 9:13am UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/5 "2021-07-27T09:13:33Z")

</div>

I appreciate the explanation. Very clear! I actually did understand the concept but I wasn’t sure what you were initially asking. Looks like you figured out how to set the value of the two-dimensional array/list but you’re wondering how to reference items of a list inside a list.

Building off of what @muneer created, this will give you the value of Array[2][2]:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/8/1/819e23e14a9995eb5fb2219ef4c74b4b2d6d113a.png)

I’d probably create a function with inputs for the row & column to simplify the process and allow you to use it repeatedly:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/a/d/ad9c314218b1330d72ef509d246c9c4bc5cfe793.png)

And here’s yet another method, perhaps the simplest:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/7/0/703e046a25100c9dc6cc47793e617f19dca5b628.png)

Note that when using the `get property of object` block, the sub-list/array index value starts at 0 unlike the `in list get #` block which starts at 1. So you’d need to use [2].1 to get the second value of 5.

In case you want to play around with these:

[https://x.thunkable.com/copy/c1d27648ec0a62e062df28d6c0a68ca6](https://x.thunkable.com/copy/c1d27648ec0a62e062df28d6c0a68ca6)

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [July 27, 2021, 9:31am UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/6 "2021-07-27T09:31:09Z")

</div>

You can even embed further (list of list of list). The syntax just gets a little tricky with the brackets’ placement. This will give you the value 32:

 ![image](https://us1.discourse-cdn.com/flex015/uploads/thunkable/original/3X/3/6/366f78dcca63684e4b8394e5190b49e1026510ef.png)

Note that the index starting values are either 0 or 1 depending on whether you’re referencing the deepest (I’m sure there’s better terminology than that…) list or not.

So for example, [1].[3].1 references [first list item]–\>[third list item].second list item

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [July 27, 2021, 10:00am UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/7 "2021-07-27T10:00:14Z")

</div>

I think you’ll like this documentation about **Nested Values and Values from Arrays** :

> **[Objects](https://docs.thunkable.com/objects#nested-values-and-values-from-arrays)**

---

<div class="post-metadata">

**Author:** ![bnice](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/bnice/32/110648_2.png) [@bnice](https://community.thunkable.com/u/bnice)\
**Post date:** [July 27, 2021, 2:08pm UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/8 "2021-07-27T14:08:00Z")

</div>

Thanks for the insight! I think this is exactly what I needed. I especially liked that you were able to go even deeper using the object properties. I figured it was going to be using something like two get blocks, but my brain was just having such a hard time fathoming what to do 🤣. I’ll make this solved. Thanks again everyone!

---

<div class="post-metadata">

**Author:** ![bnice](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/bnice/32/110648_2.png) [@bnice](https://community.thunkable.com/u/bnice)\
**Post date:** [July 27, 2021, 2:09pm UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/9 "2021-07-27T14:09:31Z")

</div>

I find it funny how the indexing changes. Again, I’m usually written coder, so the fact that for most of Thunkable I’m using row one instead of row zero for the first row drives me insane!

---

<div class="post-metadata">

**Author:** ![tatiang](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/tatiang/32/55482_2.png) [@tatiang](https://community.thunkable.com/u/tatiang)\
**Post date:** [July 27, 2021, 5:09pm UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/10 "2021-07-27T17:09:58Z")

</div>

Yep, the indexing is inconsistent. I think a big part of that is that the `get property of object` block only just recently gained the ability to use indexing values and I think it was a bit of an afterthought (although a very useful one!).

Things like that can be added to the [GitHub Feature Request/Bug section](https://docs.thunkable.com/bugs-and-feature-requests). It’s more likely they’ll be addressed when added there than when mentioned here.

There are trade-offs when making a block-based coding platform. I think they made the right choice as far as list indexing with blocks goes. I think Scratch works the same way. I can only imagine how many people would be creating topics asking “why is my list item #1 showing the value of the second list item???” otherwise. But it can certainly throw off an experienced coder.

---

<div class="post-metadata">

**Author:** ![ioannis](https://sea1.discourse-cdn.com/flex015/user_avatar/community.thunkable.com/ioannis/32/146956_2.png) [@ioannis](https://community.thunkable.com/u/ioannis)\
**Post date:** [November 8, 2024, 1:17pm UTC](https://community.thunkable.com/t/how-to-set-access-2d-list-array/1415562/11 "2024-11-08T13:17:48Z")

</div>


