You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aacb664
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: snippets/dig.md
+4-3Lines changed: 4 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -9,13 +9,14 @@ Use the `in` operator to check if `target` exists in `obj`.
9
9
If found, return the value of `obj[target]`, otherwise use `Object.values(obj)` and `Array.prototype.reduce()` to recursively call `dig` on each nested object until the first matching key/value pair is found.
10
10
11
11
```js
12
+
12
13
constdig= (obj, target) =>
13
14
target in obj
14
15
? obj[target]
15
16
:Object.values(obj).reduce((acc, val) => {
16
-
if (acc !==undefined) return acc;
17
-
if (typeof val ==='object') returndig(val, target);
18
-
}, undefined);
17
+
if (acc !==undefined) return acc;
18
+
if (typeof val ==='object') returndig(val, target);
0 commit comments