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

211
Views
Javascript - replace expression not working

while executing the following code:

let queryStr = JSON.stringify(queryObj);
console.log(queryStr);
queryStr = queryStr.replace(/\b(gte|gt|lte|lt)\b/g, (match) => {
`$${match}`;
console.log(queryStr);
});

I receive the following results from 'console.log':

{"price{gt}":"1500"}
{"price{gt}":"1500"}
  • This is my get query: http://127.0.0.1:3000/products?price{gt}=1500

Why does the replace not work? Could you help me, please?

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

0

Your code basically worked, but there were some inaccuracies. Mainly, your replace function didn't return anything, and the second log statement was in the wrong place/executed before you wanted it to be executed.

const queryObj = {"price{gt}":"1500"};
const input = JSON.stringify(queryObj);
console.log("input:", input);
const queryStr = input.replace(/\b(gte|gt|lte|lt)\b/g, (match) => `$${match}`);
console.log("queryStr:", queryStr);

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!