Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

142
Views
Use .replace() with "

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!

about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

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};
about 4 years ago · Juan Pablo Isaza Report

0

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'))

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!