I'm currently working on a Typescript project where I need to convert URL parameters into a JSON object.
The issue I'm facing is that some values are concatenated with a '+'. How can I replace this symbol with a space?
Here's the URL I'm dealing with:
let paramUrl = 'type=MERCEDES+BENZ'
This is what my code looks like:
let replace = JSON.parse('{"' + paramUrl.replace(/&/g, '","').replace(/=/g,'":"') + '"}', function(key, value) { return key===""?value:decodeURIComponent(value) })
Currently, it returns:
{type: "MERCEDES+BENZ"}
However, I actually need it to return:
{type: "MERCEDES BENZ"}