Skip to content

Instantly share code, notes, and snippets.

@AkashRajvanshi
Created November 2, 2019 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AkashRajvanshi/c03699055d008dff35ff7a8bf470c8f4 to your computer and use it in GitHub Desktop.
Save AkashRajvanshi/c03699055d008dff35ff7a8bf470c8f4 to your computer and use it in GitHub Desktop.
const user = {
firstName: 'Akash',
lastName: 'Rajvanshi',
fullname: function () {
return `${this.firstName} ${this.lastName}`
}
};
console.log(user['first' + 'Name']) // Akash
const name = 'firstName';
console.log(user[name]) //Akash
//That also allows us to access properties whoes keys are not identifiers :
const obj = {
'first Name': 456
};
console.log(obj['first Name']) // 456
const anotherObj = {
'6': 'bar'
};
console.log(anotherObj[3 + 3]) // bar (key: the string '6')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment