Object
has

Checks if the given path exists in the given object.

Syntax

import { has } from '@opentf/std';
 
has(obj: object, path: string | unknown[]): boolean

Examples

has() //=> false
 
has({}, '') //=> false
 
has({ a: undefined }, 'a') //=> true
 
has({ a: undefined }, ['a']) //=> true
 
has({ a: null }, 'a') //=> true
 
has({ a: 1 }, 'a') //=> true
 
has({ a: { b: [1, 2, 3, { c: 5 }] } }, 'a.b[3].c') //=> true
 
has({ a: { b: [1, 2, 3, { c: 5 }] } }, 'a.b[5].c') //=> false
 
has({ a: { 'b.c': 1 } }, ['a', 'b.c']) //=> true

Try