//定义对象 var person={}; console.log(person); //为对象添加属性 person['name']='tim'; console.log(person); //为对象添加属性(属性为参数变量) var attrVar='like'; person[attrVar]='basketball'; console.log(person);
打印:
Object {} Object {name: "tim"} Object {name: "tim", like: "basketball"}