Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

js hasownproperty multiple

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: #js #hasownproperty #multiple
ADD COMMENT
Topic
Name
1+2 =