Check if model contains key derbyjs

97 Views Asked by At

Is there a way to check if a property exists on a model?

var self = model.get("users."+userId);
if (! self.name.firstName){
  //do something
}
1

There are 1 best solutions below

0
msj121 On BEST ANSWER

This seems to work; however, you need to check each property one by one, since going to far down the chain might not exist.

so perhaps:

var self = model.get("users."+userId);
if (!self.name && !self.name.firstName){
  //do something
}