Advertisement
yarin0600

Untitled

Dec 12th, 2023
515
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Online Javascript Editor for free
  2. // Write, Edit and Run your Javascript code using JS Online Compiler
  3.  
  4. let obj = {details: {address: {city: "Ness Ziona", street: "Saknai"}}};
  5.  
  6. console.log(obj);
  7. console.log(obj.details);
  8. console.log(obj.details.address);
  9. console.log(obj.details.address.city);
  10.  
  11. let a = "details";
  12. let b = "address.city";
  13. let keys = `${a}.${b}`.split('.');
  14. let root = obj;
  15. const last = keys.reduce((key, root) => {
  16.     console.log(root[key]);
  17.     return root[key]}, root);
  18.  
  19. console.log(last);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement