Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function findElement(what, where) {
- if (typeof where !== 'object') return null;
- if (what in where) return where[what];
- for (let key in where) {
- let result = findElement(what, where[key]);
- if (result) return result;
- }
- return null;
- }
- const obj = {
- a: document.createElement('div'),
- b: {
- c: document.createElement('div')
- }
- };
- console.log(findElement('d', obj));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement