In the below example, unmapped array items must be mapped to rest parameter in the left hand side, but for some reason the output is different,
var planets = ["Mercury", "Earth", "Venus", "Mars", "Pluto", "Saturn"];
var [first, second, ...rest] = ["Mercury", "Earth", ...planets, "Saturn"];
console.log(first); //Output: Mercury
console.log(second); //Output: Earth
Now for the below, expected output is,
console.log(rest); //Output: ["Venus", "Mars", "Pluto", "Saturn"]
But the actual output is,
console.log(rest); //Output: "Mercury", "Earth", "Venus", "Mars", "Pluto", "Saturn", "Saturn"
Source:https://www.freecodecamp.org/news/array-destructuring-in-es6-30e398f21d10/
Whats happening here?