I came across this JavaScript function:
function myTrim(x) {
return x.replace(/^\s+|\s+$/gm,'');
}
I know that this function(mytrim()
) replaces some characters in the string(x), but what does /^\s+|\s+$/gm
do in the replace method?
Where can I learn more about these things?
Note- This function returns the string with removed spaces at both sides.