假设我有一个如下所示的对象:
var object = {
property: {
deeper: {
deepProperty: '1234'
}
}
}
我想编写一个函数,将带有点的字符串解析为适当的深层嵌套对象值:
function prop(str) {
// Should return the nested object value based on the string
}
例如:
prop('property.deeper.deepProperty')
// Should return: '1234'