The solutions described above using structuring suffer from the fact that you have a variable that can cause complaints from ESLint if you use it.
So here are my solutions:
const src = { a: 1, b: 2 } const result = Object.keys(src) .reduce((acc, k) => k === 'b' ? acc : { ...acc, [k]: src[k] }, {})
On most platforms (except IE, if Babel is not used), you can also do:
const src = { a: 1, b: 2 } const result = Object.fromEntries( Object.entries(src).filter(k => k !== 'b'))
bert bruynooghe Jun 06 '19 at 17:15 2019-06-06 17:15
source share