Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to get all the values of a table without a loop? [ANSWERED]

Hello! I don't really know how to explain it so I will use an example. So let's say I have a table:


local table = {1,2,3,4,5}

I want to get all the values without a for loop.

I don't know if there's a function for that. I don't really like doing:

table[1] or table[2] or etc...

Is there a way to do:

table[all]

Thank you in advance!

~ Matt

1 comment

0

not to my knowledge

1 answer

✓ Accepted answer

What you are trying to do is not completely possible, but there are a few ways you can achieve something similar.

You can try doing table.concat. Here's an example.

local numberTable = {"1", "2", "3"}
print(table.concat(numberTable, " "))

That would print 1 2 3.

4 comments

0

Is there a way to do it for numbers, bool values, or nil?

0

Nope, not possible. You have to use a loop.

0

Ok

0

I only needed it for strings anyway

This discussion is preserved as it was. New answers, comments, and votes are closed.