Hello coder, In this post, we learn how to find a character index in a string in JavaScript.
Here I make variable str with string value and try to find the index of “r” character.
Script
<script>
var str = 'dirask is awesome!';
const result = str.indexOf('r');
console.log(result); //0
</script>
Console result
2

Brijpal Sharma is a web developer with a passion for writing tech tutorials. Learn JavaScript and other web development technology.