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')) {
}
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).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With