Remove hyphen in between 2 words (Solved)

I use the WixLocation API to identify first and last names of the current user in a dynamic page [
let lastName = wixLocation.path[1];
let firstName = wixLocation.path[2];
]
and then proceed with some additional features. It works perfectly with one exception:
When the user has a double first or double last names (let’s suppose his first name is Jean Baptiste), then the wixLocation.path[1] gives jean-baptiste with a hyphen in the middle. And it then prevents all of my next additional features.
Is there any way I can remove this hyphen in between these two names?

Thanks for yoru reply.

Hi,

A URL cannot contain the whitespace character, therefore a hyphen is added as a filler character
You can use a loop to iterate the string characters and replace any hyphens with a whitespace character.

Hi Ido,
Can you kindly be a bit more explicit? How can I identify 1st, 2nd, … letters in a string? And replace the hyphen with a white space? Which tool from which API do I need?
Thanks,

Issue solved.

let lastN = wixLocation.path[1];
var lastName = lastN.replace(/-/g, ’ ');