Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.