If I have an object, such as,
const obj = {
a: 1,
b: 2,
c: 3,
}
I can map the keys and values as,
Object.entries(obj).map(([key, value]) => console.log(`${key}: ${value}`))
Is it possible in Javascript to omit a property, when mapping it?
Something like,
Object.entries({a: obj.a, ...obj}).map(([key, value]) => console.log(`${key}: ${value}`))
I can do the following:
Object.entries(obj).map(([key, value]) => key !== 'a' && console.log(`${key}: ${value}`))
But I feel like there can be a cleaner way to do this, and also this wouldn't work, because that mapped index will contain undefined
. Just looking to clarify this.