How to get an arrays name

Hello developers!
I’m trying to make a data store array and when I receive the data I need to know the array’s name. So I made a little sketch of how this would look.

--making array

local dataFromDataStore = {}

--getting name

local array = dataFromDataStore

--prints arrays name

print(array.Name)

So how would I go about doing that?
Just to make it clear I’m trying to get the arrays name not one of the values name
Thanks in advance!

That is not something you can do. You should try to store data in another way that allows you to, such as dictionaries.

local dict = {
     a=1,
     b=5,
     c="lemon"
}

print(dict.a, dict.b, dict.c) --prints 1 5 lemon

You can then combine this with loops to get the keys and such.

for i,v in pairs(dict) do
     print(i,v) -- will print the key name and its value in each iteration
end

This will output the following:

a 1
b 5
c lemon

Hope this helped.

1 Like