Number of array items

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

Try this is Script Console:

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

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?

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:

def transform(self, value, quality, timestamp):
	return len(self.props.data)
1 Like

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

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

Works great, thank you!

I'm still worried!

Adding items is simple.

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

Where's the tuba? :slight_smile:

1 Like

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.

1 Like