0

I want to test if an object is empty, then empty it but only if true

With something like that :

angular.isDefined(this.project.motivation.description) = {}

The problem is that angular.isDefined return a boolean. Is that it has a method with good practice without used the conditions if, with Lodash or ES2015 for example ?

Mouad Ennaciri
  • 1,217
  • 3
  • 15
  • 28

1 Answers1

1

You can do it using Lodash with _.defaultTo() function:

var f = {a: "test"}
f = _.defaultTo(f, {})

If the object is undefined, the function return the empty object.

Carlos Franco
  • 210
  • 2
  • 9