I have a props object which will contain an unknown set of properties, some of which I want to extract based on their prefix. I have something that works (great!) but it seems long-winded, and I want to know if there's a more idiomatic way of doing it?
const props = {
bingo: 1,
bongo: 2,
mingo: 3,
bango: 4
}
const bFields = {}
Object.keys(props).filter(k => (k.startsWith('b'))).forEach(k => (
bFields[k] = props[k]
))
console.log(props)
console.log(bFields)