Hey, how do I insert something like [“Part”] = {Value = 4444} into a table via table.insert? I tried but it is an error and doing {[“Part”] = {Value = 44444}} print nil out.
Thanks for helping.
local Data = {
['Part'] = {Value = 4474,14,7777},
['Part2'] = {Value = 4474,14,7777}
}
table.insert(Data,2,['Part'] = {Value = 47265})
for i, v in pairs(Data) do
print(v.Value)
end
2 Likes
You don’t use table.insert
on dictionary-like tables as function is designed to work with array-like tables. You can literally just assign them normally though:
Data['Part'] = {Value = 47265}
3 Likes
You Can Use rawset({a}, a[i], v)
instead of table.insert({a}, a[i], v)
local Data = {
['Part'] = {Value = 4474,14,7777},
['Part2'] = {Value = 4474,14,7777}
}
rawset(Data, 1, {Value = 47265})
for i, v in pairs(Data) do
print(v.Value)
end
1 Like
Which is (aside from being raw) the same as
table.insert(Data, 1, {Value = 47265})