Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

hasOwnProperty with more than one property

unction hasAllProperties(obj, props) {
    for (var i = 0; i < props.length; i++) {
        if (!obj.hasOwnProperty(props[i]))
            return false;
    }
    return true;
}

// fancy way
var props = ["a", "b"];
var obj = { "a": 1, "b": 2 };
var hasAll = props.every(prop => obj.hasOwnProperty(prop));
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #hasOwnProperty #property
ADD COMMENT
Topic
Name
1+1 =