I am currently working on getting data from an API, and I want to remove some characters from what it returns.
What I get back is {"usd":323.67}, but the currency and price may change depending on the input.
I want to remove the {}, usd (or other currency), "" and :. I searched, and found .replace() could be a good solution, if you replace the character with nothing. But when I use .replace(""", "");, I of course get an error. When I do, .replace("{}", "");, it doesn't replace the {} with nothing either. And because I use a constant for the currency, because the user can choose, the currency it not always the same, so I thought it could use .replace(${currency}`, ""), but that also doesn't work.
What should I do to remove these things from my string?
Thanks in advance!
As others commented, parse your data as JSON and then get the value using your currency variable, something like this (not sure about what framework you are using, so the currency replacement may vary from what's shown here):
data = {"usd":323.67};
value = data.${currency};
You have to find all numbers in string and then concat them with '.' symbol
const getValue = (str) => str.match(/\d+/g).join('.')
console.log(getValue('{"usd":323.67}'))
console.log(getValue('{"rub":323,67p}'))
console.log(getValue('"euro":333-00'))