Advertisement
Guest User

Untitled

a guest
Mar 9th, 2021
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.40 KB | None | 0 0
  1. function findElement(what, where) {
  2. if (typeof where !== 'object') return null;
  3. if (what in where) return where[what];
  4. for (let key in where) {
  5. let result = findElement(what, where[key]);
  6. if (result) return result;
  7. }
  8. return null;
  9. }
  10.  
  11. const obj = {
  12. a: document.createElement('div'),
  13. b: {
  14. c: document.createElement('div')
  15. }
  16. };
  17.  
  18. console.log(findElement('d', obj));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement