Find Character Index In String in Javascript

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