If I have a table with known properties, but where the order of the properties is potentially unknown:
local person = {
name = 'James',
age = 30,
}
can I reliably destructure it:
local name, age = unpack(person)
My worry is that if the order of the fields in the table is changed, that destructuring assignment will no longer work as expected.
No, there's no way to associate table fields (which are just string keys in a hash table) with local variables of the same name. You just have to be explicit and think of variables and table keys as two separate things.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With