position of a sub string in javascript

Tags

position of a sub string in javascript

<!doctype html>
<html lang="en">
 <head>
  <title>nth position of a sub string using js</title>
 </head>
 <body>
  <script>
   function getPosition(string, subString, index) {
    return string.split(subString, index).join(subString).length;
 }
 var str= "this is a Ui session";
 console.log(getPosition(str,'i', 3));
  </script>
 </body>
</html>