javascript – How to get a slice from "arguments"-ThrowExceptions

Exception or error:

All you know that arguments is a special object that holds all the arguments passed to the function.

And as long as it is not an array – you cannot use something like arguments.slice(1).

So the question – how to slice everything but first element from arguments?


seems like there is no way without converting it to an array with

var args =;

If someone posts another solution it would be great, if not – I’ll check the first one with the line above as an answer.

How to solve:

Meddling with array functions is not actually necessary.

Using rest parameter syntax is cleaner and more convenient.


function argumentTest(first, {
  console.log("First arg:" + first);

  // loop through the rest of the parameters
  for (let arg of rest) {
    console.log("- " + arg);

// call your function with any number of arguments
argumentTest("first arg", "#2", "more arguments", "this is not an argument but a contradiction");



Q. How to slice everything but first element from arguments?

The following will return an array containing all arguments except the first:

var slicedArgs =, 1);

You don’t have to convert arguments to an array first, do it all in one step.


You can “slice without slicing” by procedurally walking the arguments object:

function fun() {
  var args = [];

  for (var i = 1; i < arguments.length; i++) {

  return args;

fun(1, 2, 3, 4, 5); //=> [2, 3, 4, 5]



You should not slice on arguments because it prevents optimizations in
JavaScript engines (V8 for example). Instead, try constructing a new
array by iterating through the arguments object.

So Paul Rosiana’s answer above is correct


This can be a way:

var args = Array.from(arguments).slice(1);


You can use the method [], 1)

[].slice will return you the slice function object and you can call it as the arguments and 1 are the parameters


You can use …rest within the function to separate the first and the rest of the arguments:

function foo(arr) {
  const [first,] = arguments;
  console.log(`first = ${first}`);
  console.log(`rest = ${rest}`);
//Then calling the function with 3 arguments:

Leave a Reply

Your email address will not be published. Required fields are marked *