Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Online Javascript Editor for free
- // Write, Edit and Run your Javascript code using JS Online Compiler
- let obj = {details: {address: {city: "Ness Ziona", street: "Saknai"}}};
- console.log(obj);
- console.log(obj.details);
- console.log(obj.details.address);
- console.log(obj.details.address.city);
- let a = "details";
- let b = "address.city";
- let keys = `${a}.${b}`.split('.');
- let root = obj;
- const last = keys.reduce((key, root) => {
- console.log(root[key]);
- return root[key]}, root);
- console.log(last);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement