0

I'm using typescript and I'm receiving a value with object format, but it's a string.

Lets call it as: myVar.

MyVar have this value (image below) as string.

const string myVar = '{"value":"1"}'

How can I transform this string to object for access your value?

enter image description here

Zkk
  • 711
  • 10
  • 27

2 Answers2

4

you can use

JSON.parse('{"value": "1"}');
Elnatal Debebe
  • 276
  • 1
  • 2
  • 7
-1
const myVar: string = '{"value":"1"}'
const myVarObj = JSON.parse(myVar)
console.log(myVarObj)

Playground Link

daydreamer
  • 80,741
  • 175
  • 429
  • 691