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
  • 741
  • 13
  • 29

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
  • 87,243
  • 191
  • 450
  • 722