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")
这个只能用集合来实现。桐告在JavaScript中,常桐轮者用Array来存储和 *** 作对象:
Array:
新建:var ary = new Array()或 var ary = []
增加:ary.push(value)
删除:delete ary[n]
遍历:for ( var i=0 i <局薯 ary.length ++i ) ary[i]
var B = {C: [
["a", "枝嫌b", "c"],
[1, 2, 3]
],
D: "兆搭运族梁int"
}
var A = {
B: B,
C: B.C
}
console.log(A)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)