I have a getter in my vuex module which gets data from a nested object, then check if there is any key match to the string and push these matched objects into an array. ESLint says that for..in
loops iterate over the entire prototype chain, which is virtually never what I want. Its suggests to use Object.{keys,values,entries}
, and iterate over the resulting array.
How can I refactor this?
getUsersData({ users: { data: { users } } }) {
if (users) {
const arr = Object.keys(users.stats || {}).map(key => users.stats[key]);
const str = 'active';
const newArr = [];
arr.forEach((el) => {
const obj = {};
for (const key in el) {
if (!key.includes(str)) {
obj[key] = el[key];
}
}
newArr.push(obj);
});
return newArr;
}
return [];
}