Skip to content

Latest commit

 

History

History
24 lines (18 loc) · 699 Bytes

.verb.md

File metadata and controls

24 lines (18 loc) · 699 Bytes

Usage

const hasOwnDeep = require('{%= name %}');
const obj = { a: { b: { c: 'd' } } };

console.log(hasOwnDeep(obj, 'a'));     //=> true
console.log(hasOwnDeep(obj, 'a.b'));   //=> true
console.log(hasOwnDeep(obj, 'a.b.c')); //=> true

console.log(hasOwnDeep(obj, 'c'));     //=> false
console.log(hasOwnDeep(obj, 'a.c'));   //=> false
console.log(hasOwnDeep(obj, 'a.b.d')); //=> false

Keys with dots

Should correctly detect deeply nested keys that have dots in them.

console.log(hasOwnDeep({ 'a.b.c': 'd' }, 'a.b.c'));      //=> true
console.log(hasOwnDeep({ 'a.b': { c: 'd' } }, 'a.b.c')); //=> true
console.log(hasOwnDeep({ a: { 'b.c': 'd' } }, 'a.b.c')); //=> true