'How can I explicitly assign a receiving variable to be an array
ok, so, I was doing this before and its working:
let array = [];
if (blablabla) array = ["foo","bar"];
else array = ["this", "that"];
FunctionImUsing(array)
And then the method will receive the array correctly and no problem.
this.FunctionImUsing = function (array) {
//works with the array inside the function. No problem
}
However, I wanted to do this:
if (blablabla) FunctionImUsing(["foo","bar"]);
else FunctionImUsing(["this","that"]);
But it doesnt work. the method receives only the first element and not the full array. How can I force the receiving variable to be an array?
I tried this
this.FunctionImUsing = function (array[]) {
but Javascript wont let me do that (Unexpected Token). I wanted to force the receiving variable of a function to be an array.
Solution 1:[1]
found the issue, it was missing a [ one of the statesments. Lol
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Gabriel Costa Finkel |