# Dump stack to array

I'm new to this code-golfing thing and I'm very interested in CJam.

Is there a way to get all the current stack as an array? I think I can do it with something like [1$2$...n\$] but I would have to get the stack's length and use some kind of iterator (or use a fixed length stack... useless). But is there a way to achieve this with a single operator? The thing is I want to iterate over all the stack's elements.

Sorry if the question is obvious or seems stupid, but I'm new to this and I couldn't find anything...

• or use a fixed length stack... useless Oftentimes you do know how many items are going to be on the stack at a given time. May 25, 2017 at 1:00
• This would probably be more on-topic for Stack Overflow. May 25, 2017 at 1:01
• @Challenger5 Tips questions in general are perfectly on topic here. While some esoteric languages have found a way to SO, I doubt CJam questions would be well-received. May 25, 2017 at 2:20
• Welcome to PPCG! This is covered on cjam.readthedocs.io/en/latest, which you'll probably find useful if you're interested in learning CJam. By the way, once you earn 20 reputation, you'll be able to join us in chat. Simple questions like this one will be answered quickly in The Nineteenth Byte. May 25, 2017 at 2:23
• @Dennis Thanks. (That 11 below my username is actually my reputation, isn't it? idk I don't really understand how all this StackExchange thing work) May 25, 2017 at 2:26

## 1 Answer

An unmatched ] command will make the entire stack into an array.

1 2 3 4 ] -> [1 2 3 4]