(Reprint) JSON object using the variable names as keys

Reprinted link: https://blog.csdn.net/lihefei_coder/article/details/82499520

// The first way 
 var Key = 'name' ;
  var JSON = {}; 
 JSON [Key] = 'zhangshan' ; 
 the console.log (json.name); 

// second embodiment 
 var Key = 'name' ;
  var JSON = { 
     [Key]: 'zhangshan' 
 }; 
 the console.log (json.name);

 

Guess you like

Origin www.cnblogs.com/XingXiaoMeng/p/11839306.html