When I destructure an empty array and pass it as a parameter to my function, it appears in places that I'm not expecting.
This is how you're supposed to destructure an array into function parameters:
let test = (one, two, three) => {
console.log(one);
console.log(two);
console.log(three);
};
test(...[1, 2, 3]);
// returns 1, 2, 3
However in my case, I want to destructure an array as a single function parameter.
Sometimes this array is empty, but it otherwise only has one object. It's not working as expected:
let test = (one, two, three) => {
if (three === undefined) {
console.log("3 is undefined");
}
};
test(...[], 2, 3);
// 3 is undefined
three is undefined, but this is certainly not true, because one is undefined.
What is going on?
oneis undefined" - What do you mean by this? In your last exampleoneis notundefined, it is2.