How can I pass a new array to a function?
arrays, function, javascript, parameters
Solution
It's easier than that:
function myFunction( arr ) { ... }
Then:
myFunction([1, 2, 3, "hello"]);
In function declarations there is no type information necessary (or possible). Just list out the parameter names. Then, when you call the function, you can use the array literal notation (just like you can in any expression to instantiate an array).
Problem
This is bad practice, I know. It's just for testing, but I can't seem to get it to work. Can I pass a new, initialized array to a JavaScript function? I'm looking for the JavaScript equivalent of this C# method: ``` public void MyFunction(new string[]{"1","2","3"}) { } ``` I tried this, but to no avail: ``` function MyFunction(new array ('1','2','3')) { } ```