-1

I have the following array of data:

[
  { "id": "1001" },
  { "id": "1002" },
  { "id": "1003" }
]

I need to convert it into a single string with url parameters like this:

https://url.com/data?id=1001&id=1002&id=1003
user2534723
  • 115
  • 1
  • 2
  • 11
  • ```let u = new URLSearchParams(myParams).toString();``` [Documentation](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams) – Coolman Apr 25 '20 at 11:49

1 Answers1

1
var id_list = [
  { "id": "1001" },
  { "id": "1002" },
  { "id": "1003" }
];

var url_param = '';

for(var index in id_list ){
    if( url_param != '' ) url_param += '&';
    url_param += 'id=' + id_list[index].id; 
}

url_param = 'https://url.com/data?' + url_param;

I am sure that this will be helpful for you. :)

forevereffort
  • 432
  • 1
  • 3
  • 14