Is there object destructuring in Lua? [Quick question]
Asked by
3 years ago Edited 3 years ago
I dealt with many programming languages before and in almost all of them we had the concept of object/array destructuring which saves me tons of time and lines fo code, if you don't know what this is then basically say i have object
3 | lastName = 'somethingElseMaybe' , |
now I want to take out first and last name in a separate variables
2 | local lastName = obj.lastName |
But with object destructuring I could simply do
1 | local { name, lastName } = obj // This is javascript syntax, kinda |
so I was just wondering, is this concept found in Lua too?
**** I NEED TO EMPHASIZE THAT ****
in other programming languages when I try to destructure an object they don't look at the order, so in the example I put above in javascript syntax name, lastName
isn't following a specific order, instead javascript looks at the matching keys for those varaible names and ten assign the value of that key to the matching variable NOT CARING ABOUT IF IT MATCHES THE ORDER OR NOT, it only cares about the order when it's an array {'Name', 'lastName'}