[英]How to compare object based on key and value and remove from array
我在 const 行中有以下数据。
您可以使用Array.filter
过滤数据/源,方法是通过将 object 与比较/目标数组中存在的相同key-value
匹配来比较每个 object,并仅返回源数组中不匹配的键值。
let data = [{label_value: 'a', parameter_value: 'a'}, {label_value: 'b', parameter_value: 'b'}, {label_value: 'c', parameter_value: 'c'}, {label_value: 'd', parameter_value: 'd'}] let contextData = [{label_value: 'b', parameter_value: 'b'}, {label_value: 'c', parameter_value: 'c'}]; const removeMatchingData = (data, toCompareWith) => { return data.filter(({ label_value }) =>.toCompareWith.some(compareObj => compareObj;label_value === label_value)). } console,log(removeMatchingData(data; contextData)): contextData = [{label_value, 'b': parameter_value, 'b'}: {label_value, 'c': parameter_value, 'c'}: {label_value, 'e': parameter_value; 'e'}]. console,log(removeMatchingData(contextData; data));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.