A
A
Anastasia2021-06-15 00:55:18
JavaScript
Anastasia, 2021-06-15 00:55:18

How to convert an array to a get-like string?

Hello. I have a filter on my site that works without reloading the page. I would like that in case of reboot - the data of the form was saved. As I understand it, I just need to change the user's url with the filter parameters in parallel. As a result, I have something like this array:

{
filtr: "_created",
status: {"Принят", "Отклонён", "Завершён"},
limit: 8
}


Tell me how to convert it, so that later I can do something like this? and process it later in php...
history.pushState(null, null, '/adm?'+array);

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Yarkov, 2021-06-15
@yarkov

1. This is not an array
2. URLSearchParams

A
Anton Neverov, 2021-06-15
@TTATPuOT

The simplest is to use a module. For example, query-string . It provides a more convenient API than the native URLSearchParams .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question