let obj = {'a1':'a1'}obj['a2'] = 'a2'console.log(obj)//输出{'a1':'a1','a2':'a2'}
2、添加一个变量属性,并赋值变量,写法如下:
function add(name,value){let obj = {"a1":"a1"}obj[name] = value//返回参数console.log(obj)//{"a1":"a1","b1":"b1"}}add("b1","b1")
输出结果为:
输出结果为:
[来源] https://www.cnblogs.com/lilelile/p/10007370.html
输出结果:
循环向数组resultlist中添加age属性