Inline variable dereferencing of object field names

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Inline variable dereferencing of object field names

Sebastian Malton
When creating objects I think that having some notation to make the following easier to read

let query = {
    $pull: {}
};
query[team] = userId;

I was thinking of borrowing from the above notation and doing the following:

let query = {
    $pull: {
        [team]: userId
    }
};

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: Inline variable dereferencing of object field names

Logan Smyth
Assuming in your first example you meant

    query.$pull[team] = userId;

not

    query[team] = userId;

then your second example is already valid a ES6 computed property and does exactly what you appear to be looking for.

On Sun, Jul 23, 2017 at 8:15 PM, Sebastian Malton <[hidden email]> wrote:
When creating objects I think that having some notation to make the following easier to read

let query = {
    $pull: {}
};
query[team] = userId;

I was thinking of borrowing from the above notation and doing the following:

let query = {
    $pull: {
        [team]: userId
    }
};

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss



_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss