Reputation: 14189
I saw a javascript expression like this:
var foo = {...}[...];
can anyone explain what that means?
Best Regards
this is a code example:
var ENV_PRODUCTION = {
production: true,
development: false
}[process.ENV.NODE_ENV|| 'development'];
Upvotes: 1
Views: 74
Reputation: 840
It will return the inner value by key value see:
var foo = {
"1": "Jam",
"2":"Stuff"}[1];
var bar = {
"1": "Jam",
"2":"Stuff"}[2];
var foo = {
"1": "Jam",
"2":"Stuff"}[1];
var bar = {
"1": "Jam",
"2":"Stuff"}[2];
var jam = {
"1": "Jam",
"B":"Other Stuff"}['B'];
var foobar = {
"...": "...",
"B":"Other Stuff"}['...'];
console.log(foo, bar, jam, foobar)
Upvotes: 4
Reputation: 4489
Its a reference to element of the object.
Try in console:
var x = {a:1}['a'];
x = 1
Upvotes: 1
Reputation: 68413
This is a spread operator as per ES6
The spread syntax allows an expression to be expanded in places where multiple arguments (for function calls) or multiple elements (for array literals) or multiple variables (for destructuring assignment) are expected.
Upvotes: 0