-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
1
  • let u = new URLSearchParams(myParams).toString(); Documentation Commented Apr 25, 2020 at 11:49

1 Answer 1

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. :)

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.