I have a question about adding brackets after an array

What happens if you add something to the brackets after an array

something like this:

local arr = {}

function hello(somethinginarray)

arr[somethinginarray]

Does it try to index what you add in there, Or does it add what you add to the brackets to the array??

Please help me understand.

You would get a table looking like this:

local arr = {
       [somethinginanarray] = nil
}

-- This is basically what the table would change to if you were to do what you said and do:
function Hello(somethinginarray)
    arr[somethinginarray]
end

Hello(somethinginanarray)



It turns the table into a dictionary, which stores a “key” called “somethinginanarray”. By default unless you store something in the key like so:

local arr = {
       [somethinginanarray] = "I'm something"--stores a string within the key
}

the key will store nothing, therefore resulting in the:

  [somethinginanarray] = nil

Hope you understand

1 Like