JS how the variable as a Key object

Focus is on the use of [], as follows

var lastWord = 'last word';

var a = {
  'first word': 'hello',
  [lastWord]: 'world'
};

a['first word'] // "hello"
a[lastWord] // "world"
a['last word'] // "worl

  

Guess you like

Origin www.cnblogs.com/robinunix/p/11543775.html