const mykeys = {
'foo' : 'bar',
'tez' : 'test',
'baz' : 'test2'
}
function test(passedValue) {
//This Arrow function needs to return something else lint complains hence the undefined. Cannot use ForOf lint complains
Object.entries(mykeys).forEach(([key, val]) => {
if (key === passedValue) {
return val
}
// return undefined
})
}
Is there an elegant way to return the value where key matches passed Value. So if passed value is foo it matches key foo and returns bar. I thought object.entities was ideal to use as it has both key & value.
Lint complains when I use for of statement and where I return undefined doesn’t work as that exits the condition, but I’ve commented that out, and get the lint error below about returning a value in the arrow function.
eslint using 'forofstatement' is not alllowed no-restricted-syntax
Expect to return a value at the end of arrow function consistent return