Detecting an undefined object property

后端 未结 30 2949
花落未央
花落未央 2020-11-21 04:43

What\'s the best way of checking if an object property in JavaScript is undefined?

30条回答
  •  遥遥无期
    2020-11-21 05:35

    If you are using Angular:

    angular.isUndefined(obj)
    angular.isUndefined(obj.prop)
    

    Underscore.js:

    _.isUndefined(obj) 
    _.isUndefined(obj.prop) 
    

提交回复
热议问题