给定一个字符串数组:
const first_array = ['aaa', 'bbb', 'ccc']
Run Code Online (Sandbox Code Playgroud)
和另一个字符串数组:
const second_array = ['aaa', 'bbb', 'ccc', 'ddd', 'eee']
Run Code Online (Sandbox Code Playgroud)
如果来自的所有字符串first_array都存在于中second_array,我如何返回 true 否则返回false?
我想将我想与有效负载一起删除的条目的 id 动态传递到减速器中,并且我正在尝试删除一个对象属性(具有“eowvw698x”id 的那个是动态的并且可能会改变)并保留现有的.
case DELETE_ENTRY:
return {
...state,
diaryEntries: {
...state.diaryEntries,
??????
},
};
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
我使用了 Vencovsky 的回答和 Klaycon 的评论建议并写道:
case DELETE_ENTRY:
const { [payload]: dontcare, ...otherProperties } = state.diaryEntries;
return {
...state,
diaryEntries: {
...otherProperties,
},
};
Run Code Online (Sandbox Code Playgroud)
其他人的解决方案使状态对象发生变异,这是最高算法所禁止的。