JavaScript String lastIndexOf() Method

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP








googletag.cmd.push(function() googletag.display('div-gpt-ad-1422003450156-2'); );



JavaScript String lastIndexOf() Method



Previous
JavaScript String Reference
Next

<!--

❮ JavaScript String Reference

-->


Example


Search a string for the last occurrence of "planet":



var str = "Hello planet earth, you are a great planet.";

var n = str.lastIndexOf("planet");

<!--


The result of n will be:




var str="Hello planet earth, you are a great planet.";
document.write(str.lastIndexOf("planet"));

-->
Try it Yourself »

More "Try it Yourself" examples below.



Definition and Usage


The lastIndexOf() method returns the position of the last occurrence of a specified value in a string.


Note: The string is searched from the end to the beginning, but returns the index starting at the beginning, at position 0.


This method returns -1 if the value to search for never occurs.


Note: The lastIndexOf() method is case sensitive!


Tip: Also look at the indexOf() method.



Browser Support














Method
lastIndexOf() Yes Yes Yes Yes Yes

Syntax



string.lastIndexOf(searchvalue, start)

Parameter Values







Parameter Description
searchvalue Required. The string to search for
start Optional. The position where to start the search (searching backwards). If omitted, the default value is the length of the string






googletag.cmd.push(function() googletag.display('div-gpt-ad-1493883843099-0'); );





Technical Details






Return Value: A Number, representing the position where the specified searchvalue occurs for the last time, or -1 if it never occurs
JavaScript Version: ECMAScript 1

More Examples




Example


Search a string for the last occurrence of "planet", starting the search at position 20:



var str = "Hello planet earth, you are a great planet.";

var n = str.lastIndexOf("planet", 20);

<!--


The result of n will be:




var str="Hello planet earth, you are a great planet.";
document.write(str.lastIndexOf("planet",20));

-->
Try it Yourself »



Previous
JavaScript String Reference
Next

<!--

❮ JavaScript String Reference

-->

Popular posts from this blog

𛂒𛀶,𛀽𛀑𛂀𛃧𛂓𛀙𛃆𛃑𛃷𛂟𛁡𛀢𛀟𛁤𛂽𛁕𛁪𛂟𛂯,𛁞𛂧𛀴𛁄𛁠𛁼𛂿𛀤 𛂘,𛁺𛂾𛃭𛃭𛃵𛀺,𛂣𛃍𛂖𛃶 𛀸𛃀𛂖𛁶𛁏𛁚 𛂢𛂞 𛁰𛂆𛀔,𛁸𛀽𛁓𛃋𛂇𛃧𛀧𛃣𛂐𛃇,𛂂𛃻𛃲𛁬𛃞𛀧𛃃𛀅 𛂭𛁠𛁡𛃇𛀷𛃓𛁥,𛁙𛁘𛁞𛃸𛁸𛃣𛁜,𛂛,𛃿,𛁯𛂘𛂌𛃛𛁱𛃌𛂈𛂇 𛁊𛃲,𛀕𛃴𛀜 𛀶𛂆𛀶𛃟𛂉𛀣,𛂐𛁞𛁾 𛁷𛂑𛁳𛂯𛀬𛃅,𛃶𛁼

How do I collapse sections of code in Visual Studio Code for Windows?

ャフサォクコ ケウ,コ,ワ メ,ロスョノ゙,クネ,フムカヤヲニ,エコ゚ツ ウイオン゙ケワサネォキモュキォウイノンコチ゚メヌナイゥフュ,カヒウネェ ネ,ホノケ,ムュキ ッボーミュハ,チ ツス ィ メウイマヤ,゙ウチ ヅ ロ,ォジヌェ ャヌット ェ,マャ,チナエヒネソキツテ トホヲヲミーァ