1

Is it possible to destructure a function parameter?

For example, I would want to convert this:

Object.entries({}).find(group=> group[0] === "foo" && group[1] === "bar");

To something like this:

Object.entries({}).find([0: key, 1: value] => key === "foo" && value === "bar");

or

Object.entries({}).find([...key, value] => key === "foo" && value === "bar");
nick zoum
  • 7,216
  • 7
  • 36
  • 80

1 Answers1

1

Notice that to destruct the arrow function parameters you should do ([key, value])

Code:

const obj = {
  asdf: 'asdf',
  foo: 'bar'
};

const result = Object
  .entries(obj)
  .find(([key, value]) => key === 'foo' && value === 'bar');
  
console.log(result);
Yosvel Quintero
  • 18,669
  • 5
  • 37
  • 46