Search code examples
supertest

Is it possible to use query key parameter as variable?


Normally one can query in the following way:

  .query({
      key1: value1,
      ...
      keyN: valueN
    })

But can I use instead of "hard" key values variables?

like following:

.query({
      varKey1: value1,
      ...
      varKeyN: valueN
    })

Solution

  • Yes, it is possible. Assuming varKey1, ... varKeyN are some variables:

    .query({
      [varKey1]: value1,
      ...
      [varKeyN]: valueN
     })