4.17.11
3.10.1
2.4.2
1.3.1
_.result(object, path, [defaultValue])
This method is like _.get
except that if the resolved value is a
function it's invoked with the this
binding of its parent object and
its result is returned.
Since
0.1.0
Arguments
argument
object
path
[defaultValue]
type
Object
(Array|string)
*
description
The object to query.
The path of the property to resolve.
The value returned for `undefined` resolved values.
Returns
(array)
Example
var object = {
a: [
{ b: { c1: 3, c2: _.constant(4) } },
],
};
_.result(object, "a[0].b.c1");
// => 3
_.result(object, "a[0].b.c2");
// => 4
_.result(
object,
"a[0].b.c3",
"default"
);
// => 'default'
_.result(
object,
"a[0].b.c3",
_.constant("default")
);
// => 'default'
var object = { a: [{ b: { c1: 3, c2: _.constant(4) } }] };
_.result(object, "a[0].b.c1");
// => 3
_.result(object, "a[0].b.c2");
// => 4
_.result(object, "a[0].b.c3", "default");
// => 'default'
_.result(object, "a[0].b.c3", _.constant("default"));
// => 'default'