Created
November 2, 2019 13:59
-
-
Save AkashRajvanshi/c03699055d008dff35ff7a8bf470c8f4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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