You can't simply pass an array as a query parameter. You will need to iterate over the array and add it to the URL string such as ?array[]=one&array[]=two

const a = ['one', 'two']
let url = 'www.google.com'

for (let i = 0; i < a.length; i++) {
    // Check to see if the URL has a query string already
    if (url.indexOf('?') === -1) {
        url = `${url}?array[]=${a[i]}`
    } else {
        url = `${url}&array[]=${a[i]}`
    }
}

console.log(url)

Answer from Cjmarkham on Stack Overflow
Discussions

Sending Array Of Objects in GET request (axios)
Now I know when we want to send complex params in query we use POST method This is incorrect. You should use POST when you are adding something to a collection. If you are only retrieving data, you should still use GET. I say that knowing full well that GraphQL totally ignores that notion, but that's Facebook for you. I also don't get why you need filter to be an array of objects? Do you have an example of when the array would have many indices? I'd expect you want a GET with a query string that's something like ?name=descriptive&value=test but maybe you're not in control of your backend? IDK. qs handles query strings, not POST bodies, which (presumably) are stringified JSON. So if you're set on doing a POST with a body, you want JSON.stringify More on reddit.com
🌐 r/reactjs
11
7
April 21, 2022
java - Send an Array with an HTTP Get - Stack Overflow
How can i send an Array with a HTTP Get request? I'm Using GWT client to send the request. More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to pass an array through $.get? - Stack Overflow
So you cannot just pass an associative array unless you somehow convert it to a string value (maybe in Json format, as antisanity suggested). More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to send an array using GET request from a input form in PHP? - Stack Overflow
Explore Stack Internal ... I'm retrieving data from the database and I am using GET request to send the data to a page to delete the data. Now, I want to send an array which contains multiple tr's to delete the data and I want to do this using GET request, not POST request. More on stackoverflow.com
🌐 stackoverflow.com
September 13, 2018
🌐
YouTrack Support
youtrack-support.jetbrains.com › hc › en-us › community › posts › 360010685319-Send-an-array-parameter-in-GET-HTTP-request-using-workflow
Send an array parameter in GET HTTP request using workflow – YouTrack Support | JetBrains
I have to make HTTP GET request like this: tasks.task.get&select[]=TITLE&select[]=DESCRIPTION&select[]=RESPONSIBLE_ID&select[]=PRIORITY&select[]=STATUS&select[]=DEADLINE&select[]=PARENT_ID&select[]=UF_YOUTRACK_ID&select[]=UF_UPDATED_BY_YT&select[]=UF_COMMENT_UPDATED_BY_YT&select[]=UF_YT_TYPE_OF_WORK&select[]=UF_AUTO_218204594690 documentation says that every param must be a string, and couldn't find better way then this wrong way: ```js connection.getSync( "tasks.task.get", { 'taskId': bx_id, 'select': 'TITLE', 'select': 'DESCRIPTION', 'select': 'RESPONSIBLE_ID', 'select': 'PRIORITY', 'select'
🌐
Java2s
java2s.com › example › javascript › string-operation › send-array-with-get-request-by-appending-array-to-url.html
Send array with GET Request by appending array to URL - Javascript String Operation
<html> <head> <meta name="viewport" content="width=device-width, initial-scale=1"> <script type="text/javascript"> window.onload=function(){/*from w w w . j a v a 2 s. co m*/ var a=['one', 'two']; var url = 'www.google.com'; for (var i=0; i<a.length; ++i) { if (url.indexOf('?') === -1) { url = url + '?array[]=' + a[i]; }else { url = url + '&array[]=' + a[i]; } }
🌐
Reddit
reddit.com › r/reactjs › sending array of objects in get request (axios)
r/reactjs on Reddit: Sending Array Of Objects in GET request (axios)
April 21, 2022 -

I'm implementing filter, sorting, pagination and search functionality via API call. For filter values i have to send array of objects in parameters.

Now I know when we want to send complex params in query we use POST method. But still wants to understand.

In my application, swagger stringify does it without any issue. I can't get the same format which is as below.

e g. This is i want in request headers (payload)

filter:[{name:"descriptive", value: "test"}]

I have tried qs package and JSON.stringify

qs.stringify(params)

or with arrayFormat but not getting the above format in payload.

Instead I'm getting this, which is not acceptable

filter[0][name]: descriptive

filter[0][value]: test

any help would be appreciated.

Top answer
1 of 3
224

I know this post is really old, but I have to reply because although BalusC's answer is marked as correct, it's not completely correct.

You have to write the query adding "[]" to foo like this:

foo[]=val1&foo[]=val2&foo[]=val3
2 of 3
185

That depends on what the target server accepts. There is no definitive standard for this. See also a.o. Wikipedia: Query string:

While there is no definitive standard, most web frameworks allow multiple values to be associated with a single field (e.g. field1=value1&field1=value2&field2=value3).[4][5]

Generally, when the target server uses a strong typed programming language like Java (Servlet), then you can just send them as multiple parameters with the same name. The API usually offers a dedicated method to obtain multiple parameter values as an array.

foo=value1&foo=value2&foo=value3
String[] foo = request.getParameterValues("foo"); // [value1, value2, value3]

The request.getParameter("foo") will also work on it, but it'll return only the first value.

String foo = request.getParameter("foo"); // value1

And, when the target server uses a weak typed language like PHP or RoR, then you need to suffix the parameter name with braces [] in order to trigger the language to return an array of values instead of a single value.

foo[]=value1&foo[]=value2&foo[]=value3
_GET["foo"]; // [value1, value2, value3]
echo is_array($foo); // true

In case you still use foo=value1&foo=value2&foo=value3, then it'll return only the first value.

_GET["foo"]; // value1
echo is_array($foo); // false

Do note that when you send foo[]=value1&foo[]=value2&foo[]=value3 to a Java Servlet, then you can still obtain them, but you'd need to use the exact parameter name including the braces.

String[] foo = request.getParameterValues("foo[]"); // [value1, value2, value3]
🌐
Brian Childress
brianchildress.co › sending-array-of-values-in-get-request
Sending an Array of Values in a GET Request - Brian Childress
February 15, 2022 - Sometimes you might need to send multiple values for a given parameter in a GET request to your API. For example, you have a GET /users API endpoint and you want to lookup information on several users at once. You might want your query to look something like: /users?username=bob;sally;john.
Find elsewhere
🌐
tutorialpedia
tutorialpedia.org › blog › sending-an-array-of-values-through-the-query-parameters-of-a-get-request
How to Send an Array of Values in GET Request Query Parameters and Extract It in Node.js/Express — tutorialpedia.org
Unlike POST requests, which can include data in the request body, GET requests rely on query parameters—key-value pairs appended to the URL. But query parameters are traditionally designed for single values, so sending arrays requires specific conventions. In this guide, we’ll explore the most common methods to send arrays via GET query parameters, how to implement them in client-side code (e.g., curl, Postman, JavaScript), and how to extract and process these arrays in a Node.js/Express backend.
🌐
Snipplr
snipplr.com › view › 4444 › passing-an-array-through-get-request
Passing an array through GET request - PHP Snipplr Social Repository
Passing my 2D array as an arguement and printing all days on which an entree wil be served based on the entree entered? ... In the first example, you can use $_GET["arr"] as an array.
🌐
Stack Overflow
stackoverflow.com › questions › 52305589 › how-to-send-an-array-using-get-request-from-a-input-form-in-php › 52388560
javascript - How to send an array using GET request from a input form in PHP? - Stack Overflow
September 13, 2018 - //Use filter_input_array() function. $request = filter_input_array(INPUT_GET); //Get form inputs of array 'info' $input = $request['info']; //Get form input value foreach ($input as $key=>$value) { echo "<p>{$key}=>{$value}</p>"; }
🌐
Bubble
forum.bubble.io › need help › apis
Array Parameter in GET request - APIs - Bubble Forum
February 28, 2023 - I need to send a GET request for weather data. One of the parameters is a list. If I send a single value in that parameter, all is well. As soon as I add another value, I get an error message. (The full link works 100% i…
🌐
SitePoint
sitepoint.com › javascript
Send Array Object to jQuery Get - JavaScript - SitePoint Forums | Web Development & Design Community
December 24, 2011 - I’m trying to send my array object through ajax using the jQuery .get method, but when it sends, ids show up as multiple parameters and I’m not sure if that’s the way to do it. Here is my code: var val = []; $(':checkbox:checked').each(function(i){ val[i] = $(this).attr('id').substring(6); }); $.get("/assets/ajax/pm_change_status.php", { s: sess_id(), 'ids[]': val } );
🌐
Laracasts
laracasts.com › discuss › channels › laravel › how-to-send-array-from-script-to-controler
how to send array from script to controler
<script type="text/javascript"> function sendData() { var data = [ 1, 2, 3 ]; $.ajax({ url:'/test', type: 'POST', dataType:'json', contentType: 'json', data: JSON.stringify(data), contentType: 'application/json; charset=utf-8', }); } </script> in controller · function saveJson(Illuminate\Http\Request $request) { $data = json_decode($request->getContent()); } in app\Http\Middleware\VerifyCsfrToken ·
🌐
Derekhassan
derekhassan.dev › blog › how-to-pass-an-array-as-a-query-string-to-express
How to Pass an Array as a Query String to Express
I tried this with the Node Express server I was working with, and it turns out Express will automatically parse this as an array for you! Let's take an example. Fall is approaching and what better example to use than apples? Let's say we have an /apples endpoint that allows us to filter on different apple varieties to find price and stock. Here is a simple Express route that handles this request: app.get('/apples', (req, res) => { const apples = [ { type: 'Empire', price: '$1.20', quantityAvailable: 10, }, { type: 'Granny Smith', price: '$0.85', quantityAvailable: 8, }, { type: 'Gala', price:
🌐
GitHub
github.com › angular › angular › issues › 20797
feat: allow HTTP param encoder to vary for arrays · Issue #20797 · angular/angular
December 5, 2017 - I'm submitting a... [x] Bug report Current behavior When I send url data parameter which is an array on a GET request, only the first element is sended. let testParams = {key: 'value', array: ['v1','v2']}; this.http.get(`url`, {params: t...
Author: angular