标签:das name mda dash strong obj col div eva
1 var a = ‘id‘; 2 var str = ‘{‘+a+‘ : 12}‘ 3 var obj = eval("("+str+")");
结果:
1 obj={id:12}
1 var a=‘name‘; 2 var obj={}; 3 obj[a]=‘jack‘;
结果:
1 obj={name:‘jack‘}
1 var a=‘age‘; 2 var obj={[a]:23};
结果:
1 obj={age:23}
注意:此方法ie存在兼容问题;
————————————————————————————————————————————————
标签:das name mda dash strong obj col div eva
原文地址:https://www.cnblogs.com/willingtolove/p/10776731.html