2

I have this code snippet

      splitTopic = splitTopic.slice(1, splitTopic.length);
      let rawData = data.toString("utf8")
      let correctData = !isNaN(rawData) ? (parseFloat(rawData) % 1 === 0 ? parseInt(rawData) : parseFloat(rawData)) : rawData;
      let datapoint = splitTopic[3]
      let parsedData = { dataPoint: correctData }

What is the correct way of referencing dataPoint to create my data object parsedData.

I tried:

let parseData = {splitTopic[3]: correctData}

But it doesn't like this also

2
  • 2
    {[splitTopic[3]]: correctData}. Use bracket notation. Commented Jun 19, 2021 at 7:45
  • let parsedData = { [dataPoint]: correctData }. Wrap dataPoint in [] to make it a dynamic key Commented Jun 19, 2021 at 7:51

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.