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'
4
  • 1
    You can have a look at some good answers here that encode your query parameters: stackoverflow.com/questions/8135132/… Commented Aug 9, 2019 at 8:32
  • The output looks like a query string. How do you convert the array? Commented Aug 9, 2019 at 8:33
  • Possible duplicate of How to encode URL parameters? Commented Aug 9, 2019 at 8:33
  • @sschmeck the output is when I pass the array to httpClient.get() as parameters. Commented Aug 9, 2019 at 8:39

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.