Javascript Data Type How to - Find the last given character








Question

We would like to know how to find the last given character.

Answer


<!DOCTYPE html>
<html>
<head>
<script type='text/javascript'>
<!--from  ww  w .  java 2 s  . c  o m-->
var s = "Apple is red; Banana is yellow; Orange is orange;dummytest";
s = s.substring(0, s.lastIndexOf(";"));
document.writeln(s);

</script>
</head>
<body>
</body>
</html>

The code above is rendered as follows: