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属性
var object1={"1": 铅颤"正激局张举让三","2": "李四"}var arr=Object.keys(object1).map(function(k){
return {id:k,name:object1[k]}
})
console.log(arr)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)