js为一个对象Object添加一个新的属性和值

1,

var obj = {}; //或者 var obj=new Object();
var key = "name";
var value = "张三丰"
obj[key] = value;

2,

var obj = {};
var key = "name";
var value = "张三丰"
eval("obj.p" + key + "='" + value + "'");

原地址:https://blog.csdn.net/u011127019/article/details/59112030/

posted @ 2018-07-24 15:57  無玑小姐  阅读(56649)  评论(0编辑  收藏  举报