I am using ajax to send FormData and receiving the output in the following format
Result=A&Status=Approved&Error=&ErrorCode=00000
I want to convert the same into a JS object (key value pair)
e.g.
{Result: "A", Status: "Approved", Error: "", ErrorCode: "00000"}
I can do that using string split and other string functions or regex but since the output format is consistent i was wondering if this is a known data type and if yes is there a way to convert it using native functions?
2
Answers
Take a look at new URLSearchParams(), it should be a way better solution than string manipulation.
You can use
Object.fromEntries
in conjunction with theURLSearchParams
constructor.