javascript - Serialize an array of objects -


I have a function that asks the rest of the API. The function call looks like this:

I want to create a query string that looks:

 ? Limit = 10 & text = "test" and filter [0] .field = testfield and filter [0]. Param [value] = video and filter [1] .field = testfield2 and filter [1] .pam [value] = Image  

What's the best / fastest way about filter array in javascript?

Your friend is:

  var filter = [{field: "Testfield", "Params [Value]": "Video"}, {Field: "Testfield 2", "Params [Value]": "IMAGA"},]; Var qs = filters.map (function (filter, i) {return "filter [" + i + "] .field =" + encodeurIComponent (filter.field) + "and filter [" + i + "]. ] = "+ EncodeurIComponent (filter [" params [value] "])}). Join ("& amp;");  

Comments