JS, WeChat applet: determine whether an object contains a certain value (a certain attribute)

Determine whether an object has a certain property/a certain value hasOwnProperty

hasOwnPropertyIt is the only method in js that can judge that an attribute is defined in the object itself instead of inheriting the prototype chain. It is mainly used to judge whether there is a certain attribute in an object, and the return value is a Boolean value

var someObj = {
    
     id: '' }

someObj.hasOwnProperty('id')    // true
someObj.hasOwnProperty('name ')   // false

simple record

Guess you like

Origin blog.csdn.net/weixin_43825761/article/details/127810514