ohas
v1.0.6
Published
Helper method to see if an object has a specific key
Downloads
27
Readme
has()
Determine if a javascript object has a key. Allows for nested key detection.
Installation
With yarn
yarn add ohas
With npm
npm install ohas --save
Usage
import has from 'ohas';
const user = {
firstname: 'John',
lastname: 'Smith',
address: {
street1: '123 Road Way Blvd',
street2: 'APT 21',
city: 'Brooklyn',
state: 'NY'
}
}
const hasFirstname = has(user, 'firstname');
console.log(hasFirstname); // true
const hasCity = has(user, 'address', 'city');
console.log(hasCity); // true
const hasZip = has(user, 'address', 'zip');
console.log(hasZip); // false
const hasUser2 = has(user2, 'firstname');
console.log(hasUser2); // false