Loading ...

How to find last index of a character in javascript | CodeAsp.Net

How to find last index of a character in javascript

0 (0votes)

In this blog I will explain how to find last index of character in string with javascript. To explain that I have used lastIndexOf method of javascript.I have used on button and one text box. In below example the character to find is comma (‘,’).On click of button an alert will pop up which will display the index of last index of specified character. Below is the code :


<html xmlns="http://www.w3.org/1999/xhtml">



<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>




<input id="txtText" type="text" /><br />

<input id="txtButton" type="button" value="Test" onclick="testfunction();" />



<script type="text/javascript">

var searchCharacter=',';

function testfunction()


var txtText=document.getElementById('txtText');

var txtTextValue=txtText.value;

var index=txtTextValue.lastIndexOf(searchCharacter);








Happy Reading. !


Comments (no comments yet)

Top Posts