mirror of
https://github.com/whoisclebs/lodash.git
synced 2026-02-09 10:27:49 +00:00
Make _.result and _.set docs more consistent with _.get. [ci skip]
This commit is contained in:
@@ -9927,19 +9927,19 @@
|
|||||||
* @returns {*} Returns the resolved value.
|
* @returns {*} Returns the resolved value.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var object = { 'user': 'fred', 'age': _.constant(40) };
|
* var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
|
||||||
*
|
*
|
||||||
* _.result(object, 'user');
|
* _.result(object, 'a[0].b.c1');
|
||||||
* // => 'fred'
|
* // => 3
|
||||||
*
|
*
|
||||||
* _.result(object, 'age');
|
* _.result(object, 'a[0].b.c2');
|
||||||
* // => 40
|
* // => 4
|
||||||
*
|
*
|
||||||
* _.result(object, 'status', 'busy');
|
* _.result(object, 'a.b.c', 'default');
|
||||||
* // => 'busy'
|
* // => 'default'
|
||||||
*
|
*
|
||||||
* _.result(object, 'status', _.constant('busy'));
|
* _.result(object, 'a.b.c', _.constant('default'));
|
||||||
* // => 'busy'
|
* // => 'default'
|
||||||
*/
|
*/
|
||||||
function result(object, path, defaultValue) {
|
function result(object, path, defaultValue) {
|
||||||
if (!isKey(path, object)) {
|
if (!isKey(path, object)) {
|
||||||
@@ -9967,10 +9967,10 @@
|
|||||||
* @returns {Object} Returns `object`.
|
* @returns {Object} Returns `object`.
|
||||||
* @example
|
* @example
|
||||||
*
|
*
|
||||||
* var object = { 'a': { 'b': { 'c': 3 } } };
|
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
||||||
*
|
*
|
||||||
* _.set(object, 'a.b.c', 4);
|
* _.set(object, 'a[0].b.c', 4);
|
||||||
* console.log(object.a.b.c);
|
* console.log(object.a[0].b.c);
|
||||||
* // => 4
|
* // => 4
|
||||||
*
|
*
|
||||||
* _.set(object, 'x[0].y.z', 5);
|
* _.set(object, 'x[0].y.z', 5);
|
||||||
|
|||||||
Reference in New Issue
Block a user