共计 276 个字符,预计需要花费 1 分钟才能阅读完成。
var obj = {
"zhang":{
name:'张三',
girlfriend:{name:'阿狸',}
}
}
var path = 'zhang-girlfriend-name'
var value = '娑娜'
function setVal(){var list = path.split("-");
var th = "";
for (let i = 0; i < list.length; i++) {th += "['" + list[i] + "']";
}
eval(`obj${th}='${value}'`)
}
- 运行后果
{
"zhang":{
name:'张三',
girlfriend:{name:'娑娜',}
}
}
正文完
发表至: javascript
2020-09-17