Downvoting is okay, but at least let me know why you considered to do so.
I have learning passion to see if there is alternative solution, and that's why I asked this question with pre-research.
I'm refactoring some existing codes that "storing data at runtime" from "Object" to "Map"(https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map/).
The goal is processing the given runtime data without returning the results.
Since filter and map can be applied to Object.keys, it's clear for developers to understand what's the logic inside the process.
Old code sample,
Object.keys(givenObj)
.filter(key => { return typeof givenObj[key] === 'string' && givenObj[key] !== undefined })
.map( key => { processData(givenObj[key]) } )
It's obvious for people understanding what should be "filtered" before doing the next.
However, with "Map", the validation of value seems can only be done through either forEach or values in a new iteration.
For example,
givenMap.forEach( (value, key) => {
if ( typeof value !== 'string' || value === undefined ){
invalidHandling(key)
} else {
processData(value)
}
})
Question:
Whether if is the only way to handle the undefined value in "Map"?