主题
hasIn
js
_.hasIn(object, path)
检查 path
是否是 object
的直接属性或继承属性。
¥Checks if path
is a direct or inherited property of object
.
新增于
¥Since
4.0.0
参数
¥Arguments
object
(对象):的反面;¥
object
(Object): The object to query.path
(数组|字符串):要替换的模式。¥
path
(Array|string): The path to check.
返回
¥Returns
(布尔):如果 path
存在,则返回 true
,否则返回 false
。
¥(boolean): Returns true
if path
exists, else false
.
示例
¥Example
js
var object = _.create({ 'a': _.create({ 'b': 2 }) });
_.hasIn(object, 'a');
// => true
_.hasIn(object, 'a.b');
// => true
_.hasIn(object, ['a', 'b']);
// => true
_.hasIn(object, 'b');
// => false