Use all function arguments without having to enumerate them [duplicate]
Asked Answered
F

1

0

I have functionWithManyArguments(arg1,...,arg15).

Can I log all arguments without having to enumerate them all?

Fermata answered 28/11, 2018 at 8:39 Comment(1)
Either use rest (preferred) or argumentsFreckly
H
0

Yes, You could do something like:-

function foo(...args) {
  console.log(...args);
}
foo(1, 2, "a")

...args are rest parameters.

Houdon answered 28/11, 2018 at 8:41 Comment(1)
Unfortunately, I need to name all the arguments because every one of them are used in some logic. The reason why I need to use all of them at once is because I want to test if all args are defined else it returns an error.Fermata

© 2022 - 2024 — McMap. All rights reserved.