programming-examples/js/Object/Check if an object contains specified property.js
2019-11-15 12:59:38 +01:00

4 lines
199 B
JavaScript

function hasKey(obj, key) {
return obj != null && hasOwnProperty.call(obj, key);
}
console.log(hasKey({red: "#FF0000", green: "#00FF00", white: "#FFFFFF"}, "green"));