Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

javascript array to url params

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));
Comment

PREVIOUS NEXT
Code Example
Javascript :: mongodb find element in array 
Javascript :: else return 
Javascript :: download pdf 
Javascript :: react bootstrap navbar align right buttons 
Javascript :: jquery label with text 
Javascript :: setstate in react 
Javascript :: apps script get last row with data 
Javascript :: Next js Linking example 
Javascript :: react navbar material ui 
Javascript :: add class to html tag javascript 
Javascript :: save sort order of jquery sortable 
Javascript :: add word in string in javascript 
Javascript :: chartjs cdn 
Javascript :: javascript player movement 
Javascript :: optional chaining 
Javascript :: callback without duplicates javascript 
Javascript :: create video playlist using jquery 
Javascript :: await fetch parameters 
Javascript :: angular custom directive 
Javascript :: axios js 
Javascript :: java script hash 
Javascript :: angular 11 features 
Javascript :: alternative to setinterval 
Javascript :: date object js 
Javascript :: javascript zoom image onclick 
Javascript :: show and hide element in react 
Javascript :: how to make javascript function consise 
Javascript :: javascript export default 
Javascript :: js rename onclick function 
Javascript :: react hook usestate 
ADD CONTENT
Topic
Content
Source link
Name
4+6 =