Im pretty new to js so I hope this isnt a dumb question.
Im trying to slice the username string after a certain character ("."). This is what Ive tried so far.
Original Username: john.smith
The output I want: john
<html>
<body>
<h1>JavaScript Strings</h1>
<h2>The slice() Method</h2>
<p id="demo"></p>
<script>
let text = "John.Smith";
let result = text.slice(0, ".");
document.getElementById("demo").innerHTML = result;
</script>
</body>
</html>
There is no output with the ‘.’ parameter.
Does anyone know if there is way to slice the string at the ‘.’ or is there another function. I dont want to use an array in this case.
>Solution :
let result = text.split(".")[0];
I hope this will be helpful for you.
Thanks.