Last active
October 2, 2022 01:51
-
-
Save mike-pete/6f22669ef91ffca4330361668090a1f8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const x = { | |
a:{ | |
b:{ | |
c:'neat' | |
} | |
} | |
} | |
const loop = (object, path) => { | |
let index = 0 | |
let cur = object | |
while (index < path.length){ | |
cur = cur[path[index]] | |
index++ | |
} | |
return cur | |
} | |
console.log(loop(x, ['a','b','c'])) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const x = { | |
a:{ | |
b:{ | |
c:'neat' | |
} | |
} | |
} | |
const loop = (object, path) => { | |
path = path.reverse() | |
let cur = object | |
while (path.length > 0){ | |
cur = cur[path.pop()] | |
} | |
return cur | |
} | |
console.log(loop(x, ['a','b','c'])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment