-4

I have a function deleting all Dollar Signs from a string.

Can you tell me why

<h1 id="a"></h1>
<script>
function sec_filter_input(s){
        s = s.replace(/$/g, " ");
        return s;
    }
 
 document.getElementById('a').innerHTML = "a" + sec_filter_input("") + "a";
</script>

Returns "a a" (with a space between)? There is no $-Sign in the string, so the expected output is "aa" (without space"

Can you help me?

Ivar
  • 4,655
  • 12
  • 45
  • 50
Pascalus
  • 7
  • 3

1 Answers1

-1

Here is what you want:

function sec_filter_input(s) {
    s = s.replace(/\$/g, " ");
    return s;
}

document.getElementById('a').innerHTML = "a" + sec_filter_input("") + "a";
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1 id="a"></h1>
</body>
</html>
8HoLoN
  • 970
  • 1
  • 12