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

192
Views
remove specific query string react-router-dom v6

Hi I have an array of a query string with the same key and I wanna remove one of them:

https://example.com/something?orderby=date&orderby=price&orderby=amount

  const [searchParams, setSearchParams] = useSearchParams();
  let udpatedSearchParams = new URLSearchParams(searchParams.toString());

  const remove = (key) => {
    udpatedSearchParams.delete(key);
    setSearchParams(udpatedSearchParams.toString());
  };

remove("orderby") // => https://example.com/something?

but I wanna this:

remove("orderby","amount") // => https://example.com/something?orderby=date&orderby=price

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

0

It doesn't have the fanciest variable naming but it does the work

const remove = (key, url) => {
  let reqUrl = url.split("?");
  let paramArray = reqUrl[1].split("&");
  let result = paramArray.reduce(function (a, b) {
    console.log(b);
    if (b.split("=")[1] !== key) {
      return [...a, b];
    } else {
      return [...a];
    }
  }, []);

  return reqUrl[0] + "?" + result.join("&");
};

remove(
  "price",
  "https://example.com/something?orderby=date&orderby=price&orderby=amount"
);

output will be:

'https://example.com/something?orderby=date&orderby=amount'
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!