是否可以分解功能参数?
例如,我想将其转换为
Object.entries({}).find(group=> group[0] === "foo" && group[1] === "bar");
对于这样的事情:
Object.entries({}).find([0: key, 1: value] => key === "foo" && value === "bar");
或
Object.entries({}).find([...key, value] => key === "foo" && value === "bar");
答案 0 :(得分:1)
请注意,要破坏箭头功能参数,您应该([key, value])
代码:
const obj = {
asdf: 'asdf',
foo: 'bar'
};
const result = Object
.entries(obj)
.find(([key, value]) => key === 'foo' && value === 'bar');
console.log(result);