Checks if `path` is a direct property of `object`.
const object = { 'a': { 'b': 2 } }
const other = create({ 'a': create({ 'b': 2 }) })
hasPath(object, 'a.b')
// => true
hasPath(object, ['a', 'b'])
// => true
| Name | Type | Attribute | Description |
|---|---|---|---|
| object | The object to query. | ||
| path | The path to check. |
{
"comment": "/**\r\n * Checks if `path` is a direct property of `object`.\r\n *\r\n * @since 5.0.0\r\n * @category Object\r\n * @param {Object} object The object to query.\r\n * @param {Array|string} path The path to check.\r\n * @returns {boolean} Returns `true` if `path` exists, else `false`.\r\n * @see has, hasIn, hasPathIn\r\n * @example\r\n *\r\n * const object = { 'a': { 'b': 2 } }\r\n * const other = create({ 'a': create({ 'b': 2 }) })\r\n *\r\n * hasPath(object, 'a.b')\r\n * // => true\r\n *\r\n * hasPath(object, ['a', 'b'])\r\n * // => true\r\n */",
"meta": {
"range": [
841,
1400
],
"filename": "hasPath.js",
"lineno": 30,
"path": "C:\\Users\\beaujeup\\projects\\jsdoc-template\\examples\\lodash\\lodash-repo",
"code": {
"id": "astnode100003346",
"name": "hasPath",
"type": "FunctionDeclaration",
"paramnames": [
"object",
"path"
]
},
"vars": {
"path": "hasPath~path",
"index": "hasPath~index",
"length": "hasPath~length",
"result": "hasPath~result",
"key": "hasPath~key",
"object": "hasPath~object"
}
},
"description": "Checks if `path` is a direct property of `object`.",
"since": "5.0.0",
"tags": [
{
"originalTitle": "category",
"title": "category",
"text": "Object",
"value": "Object"
}
],
"params": [
{
"type": {
"names": [
"Object"
]
},
"description": "The object to query.",
"name": "object"
},
{
"type": {
"names": [
"Array",
"string"
]
},
"description": "The path to check.",
"name": "path"
}
],
"returns": [
{
"type": {
"names": [
"boolean"
]
},
"description": "Returns `true` if `path` exists, else `false`."
}
],
"see": [
"has, hasIn, hasPathIn"
],
"examples": [
"const object = { 'a': { 'b': 2 } }\rconst other = create({ 'a': create({ 'b': 2 }) })\r\rhasPath(object, 'a.b')\r// => true\r\rhasPath(object, ['a', 'b'])\r// => true"
],
"name": "hasPath",
"longname": "hasPath",
"kind": "function",
"scope": "global",
"___id": "T000002R000351",
"___s": true,
"filepath": "hasPath.js"
}