I have a Javascript object :
const mapping = {
'Mind Management': {
type: 'average',
linked_topics: ['Digital Detox', 'Small Scaling', 'Simplexity'],
edge: 'Zeroed Out'
},
'Ancient Wisdom': {
type: 'direct',
edge: 'Roots Revival'
}
};
I want to iterate through this object and check if the key
or the linked_topics
(if present) of the object matches a string value.
const stringToBeMatched = 'Simplexity'
Code that I tried:
for (var key in mapping) {
if(key === stringToBeMatched || mapping[key].linked_topics.includes(stringToBeMatched) ) {
console.log(`found ${stringToBeMatched} in ${key}`);
}
}
I'm getting the following eslint error with this:
ESLint: 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.(no-restricted-syntax)
How can this be fixed? Is there any better way to achieve this without using for..in?