table.getn is deprecated – How can I get the length of an array?

Use #:

> a = {10, 11, 12, 13}
> print(#a)
4

Notice however that the length operator # does not work with tables that are not arrays, it only counts the number of elements in the array part (with indices 1, 2, 3 etc.).

This won’t work:

> a = {1, 2, [5] = 7, key = '1234321', 15}
> print(#a)
3

Here only (1, 2 and 15) are in the array part.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)