Reputation: 435
I am relatively new to es6. I came across the following syntax and can't figure out what is it called.
let parameter = 'key1';
const obj = {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3',
}[parameter];
Upvotes: 2
Views: 99
Reputation: 20401
Statement 1: variable declaration and definition.
Statement 2: variable declaration, inline object definition and accessing it using an indexer.
FYI: your code is plain old JavaScript. Only the const
and let
keywords are ECMAScript 6.
Upvotes: 0
Reputation: 72967
That concept is not specific to ES6.
That's just an object, out of which you're getting 1 value, depending on the parameter
.
It is similar to:
let parameter = 'key1';
const temp = {
'key1': 'value1',
'key2': 'value2',
'key3': 'value3',
}
const obj = temp[parameter];
Except temp
is never declared.
Upvotes: 2