tablica JavaScript do parametów URL

const params = [
  {
    key: 'name',
    value: 'John',
  },
  {
    key: 'age',
    value: '30',
  },
];

const arrayToUrlParams = (url, array) => {
  array.forEach((item, index) => {
    if (index === 0) {
      url += `?${item.key}=${item.value}`;
    } else {
      url += `&${item.key}=${item.value}`;
    }
  });
  return url;
}

console.log(arrayToUrlParams('https://example.com', params));
SunflowerToad