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

214
Views
how to set array in URL query param

I have multi-checkbox inputs. if checked, I want set query params like this:

topic[]=1&topic[]=2&...

please help me resolve this problem

this is my code for unique param:

const addQueryParam = (name, value) => {
  const urlParam = new URL(window.location.href);
  if (!value) {
    urlParam.searchParams.delete(name);
  } else {
    urlParam.searchParams.set(name, value);
  }
  window.history.pushState({ path: urlParam.href }, "", urlParam.href);
};

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

0

You can build the query params with something like this:

// Values I want to pass by queryParams
const params = { name: 'Jhons', multiCheckbox: [1, 2, 3], ...otherValues};

Then I go through the object to build the string that I will pass to the query params

let queryParams = ''; 
Object.keys(params).map(key => {
  if (Array.isArray(params[key])) {
    queryParams += params[key].map((value) => `${key}[]=${value}`).join('&')
  }
  queryParams += `${key}=${params[key]}&`
})

Print the queryParams to get something like this:

'name=Jhons&multiCheckbox[]=1&multiCheckbox[]=2&multiCheckbox[]=3'
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!