How would I create a stack in JavaScript

What is the syntax?
I checked mdsn No code example is currently available or this language may not be supported

of these

var test : List.<int> = new List.<int>();
var stack : Stack.<int> = new Stack.<int>();
var queue : Queue.<int> = new Queue.<int>();

only List works.
the others give:

'System.Collections.Stack' is not a generic definition.
'System.Collections.Queue' is not a generic definition.

What does this mean?

Thanks!

Apparently you didn’t do “import System.Collections.Generic;”. MSDN doesn’t cover Unityscript, which is unique to Unity, so there will never be any Unityscript code examples there.

–Eric

thanks Eric!
Do you happen to know what’s difference between

var stack : Stack.<int> = new Stack.<int>();
var stack : Stack = new Stack();

The same difference as List. vs. Array…Stack is a lot slower and not type-safe compared to Stack.. Like Array, you can put anything in Stack, whereas for example Stack. is limited to ints and Stack. would be limited to floats. But you almost always want to have one type in a stack anyway, so there’s rarely a reason to use Stack when you can use Stack..

–Eric

Exactly the answer I was looking for. Thank you kind sir.

By the way, it’s better to use the number of elements you think the stack will likely have when declaring it.

var stack : Stack.<int> = new Stack.<int>(100);
// stack has room for 100 elements, so Push is faster,
// unless the stack exceeds 100 elements

–Eric