Why arr does not represent all arguments?

Hello,
I am having one question from one challenge that is puzzling me.
In the code below, why arr does not represent all arguments “[1, 2, 3, 1, 2, 3], 2, 3” as a 2-D array?
Instead, arr below only represents [1, 2, 3, 1, 2, 3].


function destroyer(arr) {
  return arr;
}
destroyer([1, 2, 3, 1, 2, 3], 2, 3);

Thank you.

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

Thank you.
I will do this next time when posting partial of codes.

the first argument is stored in the first parameter, the second argument in second parameter, etc
in this case only one parameter is present, but three arguments, so only first argument is stored in a parameter, the others you will have to access in other way

3 Likes

Thank you for the explanation.
This is a bit puzzling since it is not often seen.
Usually the number of arguments match the ones of parameters.
So the comma is the delimiter to define each individual argument I assume.
The single parameter does not take whole arguments as a 2-D array one.

Good explanation by ieahleen.
In order to get multidimensional array for your example, you need to console log this:

function destroyer(arr) {
  return arr;
}

console.log(destroyer([[1, 2, 3, 1, 2, 3],[ 2, 3]])); //Output is [[1, 2, 3, 1, 2, 3],[ 2, 3]]
1 Like

I would look at the arguments object:

1 Like

Thank you all for helps. :slightly_smiling_face: