问题
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");
回答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);
来源:https://stackoverflow.com/questions/57198633/destructure-an-array-parameter