1.1.2 • Published 10 years ago
object-has-property v1.1.2
Object-has-property
Determine if an Object has required property or properties
Information
NPM Package: Object-has-property
Description: Determine if an Object passed in first argument has required property passed in second argument. There is possibility to pass an Array of properties in second argument to check for multiple properties.
Returns False if first argument is not an Object
Returns False if second argument is not an Array nor String
Returns False if type of any properties is Undefined
Returns True if property is found in Object.prototype
Usage
Install
$ npm install --save object-has-propertyExamples
var has = require('object-has-property');
var a = {
foo: 'bar'
};
console.log(has(a, 'foo'));Outputs true
var has = require('object-has-property');
var a = {
foo: 'bar'
};
var required = [
'foo',
'missing'
];
console.log(has(a, required));Outputs false because property missing is not found
var has = require('object-has-property');
var a = {
foo: 'bar',
notmissing: 'wohoo'
};
var required = [
'foo',
'notmissing'
];
console.log(has(a, required));Outputs true
var has = require('object-has-property');
var a = {
foo: 'bar',
notmissing: undefined
};
var required = [
'foo',
'notmissing'
];
console.log(has(a, required));Outputs false because notmissing is undefined
var has = require('object-has-property');
console.log(has(Object.prototype, 'hasOwnProperty'));