The following logic works as intended. I have no means to change the lint rules.
data in this case is just an Object such as follows which gets passed in.
const testData = {
item_one: 'item',
};
This is the function which takes in above data
const convert = (data) => {
for (const key in data) {
// ...
}
return data;
};
Getting lint errors as follows for my for loop as follows:
- for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array
- The body of a for-in should be wrapped in an if statement to filter unwanted properties from the prototype
To address point one, tried to switch the loop to be of type foreach as follows and that resolves the lint.
But that has broken my logic for some reason... Bit frustrating for logic to break due to lint.
data.forEach((previousKey) => {
// ... same logic as above inside that loop loop
}
For point 2, I do want to iterate over every property. How could I resolve this lint error?
Please advice. Thank you.