Passing params in URL from React-Native

I want to pass search parameters to a request URL while calling it from React-Native framework using the code as below


const obj = {
  param1: 'val1',
  param2: 'val2',
  param3: 'val3'
}


const setQuery = (key, value) => {
  let obj_url = new URL(window.location.href);
  let params = obj_url.searchParams;
  params.set(key, value);
  console.log(obj_url.search)
}


for (let i = 0; i < Object.keys(obj).length; i++) {
  setQuery(Object.keys(obj)[i], Object.values(obj)[i])
}


I am expecting the request URL to be like


localhost/index?param1=val1&param2=val2&param3=val3


but i am getting


localhost/index?param3=val3