Recently I discovered that ES7(Ecma Script 7) has a really clever way of copying an object while omitting certain properties.

I thought I would quickly show that and also how to do the same thing with lodash.

With Lodash

1
2
3
4
5
6
import _ from 'lodash'
const animalObject = { 'bear': 1, 'snake': '2', 'cow': 3 };
 
const newObject = _.omit(animalObject, ['bear', 'cow']);

// newObject is:  { 'snake': '2' }

With ES7

1
2
3
4
5
const animalObject = { 'bear': 1, 'snake': '2', 'cow': 3 };
 
const {bear, ...other} = animalObject

// other is: { 'snake': '2', 'cow:'  3}

Pretty cool right?