jonschlinkert / data-store

Easily get, set and persist config data. Fast. Supports dot-notation in keys. No dependencies.
https://github.com/jonschlinkert
MIT License
160 stars 27 forks source link

How to pass a variable as key #41

Closed MinhVu2711 closed 2 years ago

MinhVu2711 commented 2 years ago

I have a variable name 'symbol' which content crypto's symbol (Exp: DIA) But when I use ${symbol} an error 'Property assignment expected' appears. Here is my code:

store.set(`${id_user}`, {
      `${symbol}`: {
        price_set: ctx.state.price_set,
        percent: ctx.state.percent,
        status: ctx.state.status
      }
    }
); 

What I should do to have data in JSON file storage like below???

{
  "844827665": {
    "DIA": {
      "price_set": 1.8223378037209135,
      "percent": "10",
      "status": "up"
    }
  }
}

Tks for reading my issue. Have a good day, sir