0

I am developing a website in reactjs -- and the server side api - seems to want to take array params like this. --

"order_by[0]=director_first_name asc&order_by[1]=trading_name&filter_by[0]=trading_name like a%&filter_by[1]=star_rating > 1&filter_by[2]=number_of_employees > 1"

but I am unsure if I need to create a string that looks like this - or if its a case of building the array in javascript then doing a JSON.parse() before it gets pushed into the axios call?

--

I've tried creating an array of strings like this

let orderBy = []
orderBy.push("director_first_name asc");
orderBy.push("trading_name");

then would I just wrap around a JSON.Parse when attaching it to the url string?

-- tried this but this hasn't worked https://jsfiddle.net/nk5Ly6hf/1/

==== would something like this work -- but then the arrays haven't been given pointers - https://jsfiddle.net/nk5Ly6hf/3/ aka filter_by[0], filter_by[1]

The Old County
  • 89
  • 13
  • 59
  • 129

1 Answers1

0

in the end I just built a function to create a string,

  flatArrayToString(key, arr){
      let output = "";

      for (var i = 0; i < arr.length; i++) {
        output += "&"+key+"["+i+"]="+arr[i];
      }

      return output;
  }
The Old County
  • 89
  • 13
  • 59
  • 129