Sign in to follow this  
Followers 0
sumone4life

Array Length

5 posts in this topic

This is going to sound like a rediculous newbie question but i really cant find it anywhere. How do i get the index of the last term in an array?

Share this post


Link to post
Share on other sites



what is the -1 for? ive seen that a couple times and i dont understand what it is for.

Share this post


Link to post
Share on other sites

because an array starts at $array[0] not $array[1]

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Arrays in AutoIt use a 0-based index. That means the first element is #0. This then means that the index of the last element would be one less than the actual number of elements. Like so:

$array[0] = "first element"

$array[1] = "second element"

$array[2] = "third and last element"

Ubound($array) would return 3, the total number of elements. To access the 3rd element ($array[2]), you would use an index of 2, hence the -1.

Edit: typos

Edited by mikehunt114

IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0