Untitled

mail@pastecode.io avatar
unknown
javascript
2 years ago
471 B
0
Indexable
Never
const _ = require('lodash')

const initialObject = { name: 'tester', age: 10, targeting: '#tester #messi', complaints: [1, 2] }
const changedObject = { name: 'tester', age: 11, targeting: '#tester #messi #ronaldo', complaints: [1, 2, 3] }
const changes = _.reduce(
  changedObject,
  function (result, value, key) {
    return _.isEqual(value, initialObject[key]) ? result : result.concat({ field: key, changedValue: value })
  },
  []
)

console.log(changes)