Retrieving number of elements in an array

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
tasdvl9
Posts: 94
Joined: Fri Dec 06, 2013 3:55 am

Retrieving number of elements in an array

Post by tasdvl9 »

Hi Everyone,

I've been looking all over for a simple way to retrieve the number of elements in an array.
Is there a function which returns this?

For instance, say I have an array called myArray and within it has 32 elements.
How do I acquire this info?

Thanks!
FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10103
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Retrieving number of elements in an array

Post by FourthWorld »

You can get the keys of an array, which is a return-delimited list, from which you can get the number of lines.

For arrays with consistent integer keys, you may also be able to use the extents function, but note it's limitations in the Dictionary before relying on it, as its only works with certain types of key ranges.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Thierry
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 875
Joined: Wed Nov 22, 2006 3:42 pm

Re: Retrieving number of elements in an array

Post by Thierry »

You can get the keys of an array, which is a return-delimited list, from which you can get the number of lines.
This solution is great for one dimensional arrays.

Thierry
!
SUNNY-TDZ.COM doesn't belong to me since 2021.
To contact me, use the Private messages. Merci.
!
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10502
Joined: Wed May 06, 2009 2:28 pm

Re: Retrieving number of elements in an array

Post by dunbarx »

Richard, Thierry,

This was similar to a recent thread, where someone wanted to get "the elements of the second nested level of an array". Or the fifth.

Might this warrant a feature request;

get arrayElements(arrayName,depth)

Craig
Post Reply