How to correctly use axios params with arrays in JavaScript ? Last Updated : 28 Apr, 2025 Summarize Comments Improve Suggest changes Share Like Article Like Report In this article, we will be going to learn about how to correctly use Axios params with arrays in Javascript. While making HTTP requests in Axios with arrays as parameters in JavaScript, one needs to serialize the array in such a way that the server can understand it easily. These are the following ways to use Axios params with arrays: Table of Content Using the URLSearchParams Using the map methodUsing the URLSearchParams URLSearchParams() allows you to perform multiple operations of append, delete, or getting and setting the key value in a URL Path. We are using the URLSearchParams() class to serialize the array and pass it in an Axios HTTP request to get the desired response from the API. We can pass the URL Path in the constructor as well or we can leave it empty because URLSearchParams Constructor does not parse full URL strings.Example: This example shows the implementation of the above-explained approach. JavaScript const axios = require('axios'); // Example array const arr = [1, 2, 3, 4, 5]; // Using URLSearchParams class const params = new URLSearchParams(); arr.forEach((value, index) => { params.append(`arr[${index}]`, value); }); //HTTP GET request to fetch data using Axios axios.get('https://example.com/api/data', { params }) .then(result => { // Handle the response console.log(result.data); }) .catch(error => { // Handle errors console.error(error.message); }); Output: https://example.com/api/data?arr[0]=1&arr[1]=2&arr[2]=3&arr[3]=4&arr[4]=5Using the map methodIn this, you need to manually create a URL or query string of the API to make a HTTP request. However you can customize your most complicated URL string more easily with this method but it is not convenient to use such practices.Example: This example shows the implementation of the above-explained approach. JavaScript const axios = require("axios"); // Example array const arr = [1, 2, 3, 4, 5]; // Manually create the URL string const URLString = arr.map((value, index) => `arr[${index}]=${value}`).join('&'); // HTTP GET request to fetch data using Axios axios.get(`https://example.com/api/data?${URLString}`) .then(result => { // Handle the response console.log(result.data); }) .catch(error => { // Handle errors console.error(error); }); Output: https://example.com/api/data?arr[0]=1&arr[1]=2&arr[2]=3&arr[3]=4&arr[4]=5 Comment More infoAdvertise with us Next Article How to Create Query Parameters in JavaScript ? V vivekchaudharyy Follow Improve Article Tags : JavaScript Web Technologies Geeks Premier League Geeks Premier League 2023 Similar Reads How to Make GET call to an API using Axios in JavaScript? Axios is a promise-based HTTP client designed for Node.js and browsers. With Axios, we can easily send asynchronous HTTP requests to REST APIs and perform create, read, update and delete operations. It is an open-source collaboration project hosted on GitHub. It can be imported in plain JavaScript o 3 min read How to pass an array as a function parameter in JavaScript? Here are different ways to pass an array as a function paramter in JavaScript.1. Using apply() MethodThe apply() method invokes a function with a specified `this` value and an array of arguments. It takes two parameters: the first is the `this` context for the function, and the second is an array of 2 min read How to make POST call to an API using Axios.js in JavaScript ? Axios is a promise-based HTTP client designed for Node.js and browsers. With Axios, we can easily send asynchronous HTTP requests to REST APIs and perform create, read, update and delete operations. It is an open-source collaboration project hosted on GitHub. It can be imported in plain Javascript o 2 min read How to Create Query Parameters in JavaScript ? Creating query parameters in JavaScript involves appending key-value pairs to a URL after the `?` character. This process is essential for passing data to web servers via URLs, enabling dynamic and interactive web applications through GET requests and URL manipulation. Example: Input: {'website':'ge 3 min read How to Convert Object to Array in JavaScript? In this article, we will learn how to convert an Object to an Array in JavaScript. Given an object, the task is to convert an object to an Array in JavaScript. Objects and Arrays are two fundamental data structures. Sometimes, it's necessary to convert an object to an array for various reasons, such 4 min read How to Declare an Array in JavaScript? Array in JavaScript are used to store multiple values in a single variable. It can contain any type of data like - numbers, strings, booleans, objects, etc. There are varous ways to declare arrays in JavaScript, but the simplest and common is Array Litral Notations. Using Array Literal NotationThe b 3 min read Like