【发布时间】:2019-12-21 05:50:11
【问题描述】:
我最近在尝试过滤数组时遇到了一个错误,但有时当我记录整个数组(在任何过滤之前)时,数组会丢失项目。当我多次调用此函数时会发生这种情况,是否有解决方法?
这是过滤数组的代码,我按照建议使用了 .find() 但原始数据仍在被覆盖:
let newData = dataCorte
// Log variables
console.log('Type:',args.tipo);
// Log the WHOLE ARRAY, it has two items ALWAYS
console.log('Original Data:', dataCorte.e);
// Filter the array into a new variable
let found = newData.e.find(item => {
return item.id === args.tipo
})
// Log the WHOLE ARRAY, it has two items ALWAYS
console.log('Original Data:', dataCorte.e);
// Assign the found object into the 'e' array
newData.e = [found]
console.log('================================');
// Return the new data
return newData
【问题讨论】:
标签: javascript graphql apollo