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

How Can I Index Numbers In A Table?

Asked by
Hacreey 49
5 years ago

I'm storing numbers in a table like this:

local table = {231, 5353, 2867}

I'd like to know if there's a possible way to index those values like this:

table[5353]

I thought about changing the table format to {[231] = true} however that method won't work with JSONEncode. If anyone knows a possible solution, please let me know.

Also, i'm trying to avoid having to loop through the table just to make things easier.

1 answer

Log in to vote
0
Answered by 5 years ago

In the Lua language, [] is not used to index table values. The second script bar would represent the 5,353rd value in the "table" table.

0
Is there any possible way to check if there's a value in the table without looping? Hacreey 49 — 5y
0
you could check for specific slots in the table, although it is not suggested User#28017 0 — 5y
Ad

Answer this question