# Number of array items

**URL:** <https://forum.inductiveautomation.com/t/number-of-array-items/90881>\
**Category:** Ignition\
**Tags:** scripting, perspective\
**Created:** [May 24, 2024, 3:54pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881 "2024-05-24T15:54:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [May 24, 2024, 3:54pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/1 "2024-05-24T15:54:54Z")

</div>

What is the function/script to get the number of array items from an array?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 24, 2024, 3:57pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/2 "2024-05-24T15:57:25Z")

</div>

Try this is Script Console:

```python
band = ["piano", "bass", "drums", "sax"]
print len(band)

```

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [May 24, 2024, 4:02pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/3 "2024-05-24T16:02:40Z")

</div>

So the goal here would be to take the length of the array and pass it to another tag. Ultimately trying to make a for loop to increase the length but wanting to stop when that length reaches a specific value. I am more wondering what the get value expression would be to have a temp tag hold the integer value for length of the array. Do you know what that would look like to get the array length from a property in perspective?

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 24, 2024, 4:10pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/4 "2024-05-24T16:10:01Z")

</div>

It's not clear what you are trying to do. It's also a little worrying that you are using tags for this so if you explain more what the _real_ problem you are trying to solve we may be able to offer a better solution.

Meanwhile, some examples:  
Here's a binding on a Table component custom property to return the number of rows in `props.data`.  
`len({this.props.data})`

In a script on the table it looks pretty similar:

```python
def transform(self, value, quality, timestamp):
	return len(self.props.data)

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 24, 2024, 4:12pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/5 "2024-05-24T16:12:42Z")

</div>

You wouldn't need the length, another example using the list above.

```python
band = ["piano", "bass", "drums", "sax"]
for instrument in band:
     print instrument

```

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [May 24, 2024, 4:14pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/6 "2024-05-24T16:14:22Z")

</div>

Works great, thank you!

---

<div class="post-metadata">

**Author:** ![Transistor](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/transistor/32/3380_2.png) [@Transistor](https://forum.inductiveautomation.com/u/Transistor)\
**Post date:** [May 24, 2024, 4:17pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/7 "2024-05-24T16:17:05Z")

</div>

I'm still worried!

Adding items is simple.

```python
band = ["piano", "bass", "drums", "sax"]
band.append("guitar")
print band

```

---

<div class="post-metadata">

**Author:** ![jlandwerlen](https://avatars.discourse-cdn.com/v4/letter/j/bc8723/32.png) [@jlandwerlen](https://forum.inductiveautomation.com/u/jlandwerlen)\
**Post date:** [May 24, 2024, 4:20pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/8 "2024-05-24T16:20:02Z")

</div>

Where's the tuba? 🙂

---

<div class="post-metadata">

**Author:** ![ColeS](https://avatars.discourse-cdn.com/v4/letter/c/65b543/32.png) [@ColeS](https://forum.inductiveautomation.com/u/ColeS)\
**Post date:** [May 24, 2024, 4:34pm UTC](https://forum.inductiveautomation.com/t/number-of-array-items/90881/9 "2024-05-24T16:34:16Z")

</div>

No need to be worried, I have a while loop referencing the length of the array, I set i = len(self.prop.data) works exactly how I wanted it to. It's not an easy chunk of code to explain but you helped with the question I had. Works like a dream.
