Skip to content Skip to sidebar Skip to footer

Destructure An Array Parameter

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');

Solution 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);

Post a Comment for "Destructure An Array Parameter"