1

I like using destructure parameters in my functions but occasionally I want to get the entire object passed without reconstructing it.

function foo({a, b, c, d, e}) {
   // How to get obj here?
}
foo(obj);

How can I get obj without resorting to:

let obj = {a, b, c, d, e}

The arguments variable is probably the key but it's an array(-like) object without the names.

Marc
  • 13,011
  • 11
  • 78
  • 98
  • 3
    Why not just write `function foo(obj) { const {a, b, c, d, e} = obj; ... }`? – Heretic Monkey Jul 06 '21 at 19:09
  • 1
    `arguments[0]` will give you the object, but really you just should do the destructuring separately (not in the parameter declaration) – Bergi Jul 06 '21 at 19:10
  • *"The arguments variable is probably the key but it's an array(-like) object without the names."* - Your function only has one parameter which is the object that you want (as Bergi said). – Đinh Carabus Jul 06 '21 at 19:13
  • Thanks @Bergi that is the correct answer. – Marc Jul 07 '21 at 13:05

0 Answers0