Skip to content

Function: has()

ts
function has(object, path): boolean;

Checks whether an object has a property at the given path. 判断对象在指定路径上是否存在属性。

Parameters

ParameterTypeDescription
objectunknownSource object / 源对象
pathstring | readonly PropertyKey[]Property path / 属性路径

Returns

boolean

True when the path exists / 路径存在则为 true

Example

ts
has({ a: { b: 1 } }, 'a.b')
// => true

Since

1.2.0

Released under the MIT License.