0

I'm new to typescript, can someone help me convert this PHP array to be converted to query parameter

$array = [
    'sort' => [
        'column1' => 'asc',
        'column2' => 'desc',
    ],
];

// expected query 
'sort%5Bcolumn1%5D=asc&sort%5Bcolumn2%5D=desc'

I tried it on typescript but when it gets converted to query string, it becomes an object.

let array = [];
array['sort'] = {
    'column1': 'asc',
    'column2': 'desc'
};

// it gets converted to this
'sort=%5Bobject%20Object%5D'
suh_dude-
  • 1
  • 2
  • 1
    You can have a look at some good answers here that encode your query parameters: https://stackoverflow.com/questions/8135132/how-to-encode-url-parameters – ford04 Aug 09 '19 at 08:32
  • The output looks like a query string. How do you convert the array? – sschmeck Aug 09 '19 at 08:33
  • Possible duplicate of [How to encode URL parameters?](https://stackoverflow.com/questions/8135132/how-to-encode-url-parameters) – ford04 Aug 09 '19 at 08:33
  • @sschmeck the output is when I pass the array to httpClient.get() as parameters. – suh_dude- Aug 09 '19 at 08:39

0 Answers0