function optionalChaining(obj, chain) { // your code here let key = chain.split('.'); let len = key.length, res; key.map( function (value, index) { obj = obj[value]; if (obj) { if (index === len-1) { console.log(obj) } } else { console.log(obj); } }, obj) }