Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Why my loop dont print all thing in my table?

Asked by
DAHUI84 25
2 years ago
Edited 2 years ago

I trying to print all thing in this table but it dont work.

local t = {
    ["Hello"] = 2,
    ["World"] = 3
}

for i = 1, #t do
    print(t[i])
end

1 answer

Log in to vote
1
Answered by 2 years ago

Use an generic loop to read table with key for index.

local t = {
    ["Hello"] = 2,
    ["World"] = 3
}

for i, v in next, t do
    print(i, v)
end
1
Ohh is named "generic" DAHUI84 25 — 2y
Ad

Answer this question