<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mura0083</title>
    <description>The latest articles on DEV Community by Mura0083 (@mura0083).</description>
    <link>https://dev.to/mura0083</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F728942%2F04bd4827-bc3a-4a3e-89a2-55d3fc66e170.png</url>
      <title>DEV Community: Mura0083</title>
      <link>https://dev.to/mura0083</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mura0083"/>
    <language>en</language>
    <item>
      <title>String.prototype.indexOf() vs String.prototype.lastIndexOf()</title>
      <dc:creator>Mura0083</dc:creator>
      <pubDate>Mon, 18 Oct 2021 11:01:44 +0000</pubDate>
      <link>https://dev.to/mura0083/stringprototypeindexof-vs-stringprototypelastindexof-3b6i</link>
      <guid>https://dev.to/mura0083/stringprototypeindexof-vs-stringprototypelastindexof-3b6i</guid>
      <description>&lt;h2&gt;
  
  
  "indexOf()" Description:
&lt;/h2&gt;

&lt;p&gt;The indexOf() method is used to return the index of a value/parameter's first appearance, from within a called string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;indexOf(value)&lt;/li&gt;
&lt;li&gt;indexOf(value, fromIndex)&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  "Value" and "fromIndex":
&lt;/h2&gt;

&lt;p&gt;The value is the string whose index we're looking for, from within the original string variable. For example:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Fz4LK7JK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ass5llodzi7ty7abmhbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Fz4LK7JK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ass5llodzi7ty7abmhbn.png" alt="Screenshot example1"&gt;&lt;/a&gt;&lt;br&gt;
This method looks for the value starting from left to right to find the first occurrence of the value.&lt;/p&gt;

&lt;p&gt;If value is not in the original string, such as "b", the output will come as -1. &lt;/p&gt;

&lt;p&gt;The fromIndex is an optional parameter(value from 0 to string.length) that lets you choose the index where the search starts from. If fromIndex is not specified, the search automatically starts from index 0. &lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&gt;

&lt;p&gt;Output is the index of the value in the original string, so it can be any number from 0 to string.length - 1.&lt;/p&gt;

&lt;p&gt;If the value is a string with multiple letters or numbers, the output/index will be positioned where the value starts, from the left. For example:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Vj-VXbjy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59a3zxmb0t7ldg6dn46f.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Vj-VXbjy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/59a3zxmb0t7ldg6dn46f.png" alt="Screenshot example2"&gt;&lt;/a&gt;&lt;br&gt;
The string "great" is going to have the output of "10" because the "g" stands at that index and that's where the string starts.&lt;/p&gt;

&lt;h2&gt;
  
  
  "lastIndexOf()" Description:
&lt;/h2&gt;

&lt;p&gt;The lastIndexOf() is a method that returns the index of a specified value's last appearance in the original string.&lt;/p&gt;

&lt;h2&gt;
  
  
  Syntax:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;lastIndexOf(value)&lt;/li&gt;
&lt;li&gt;lastIndexOf(value, fromIndex)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Note: Value and fromIndex stay the same as for "indexOf" &lt;/p&gt;

&lt;h2&gt;
  
  
  Output:
&lt;/h2&gt;

&lt;p&gt;This time, the method is looking for the last time our value appears in the string, then output the index. For example:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yMOqCRxI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn28zlp0cmrpqvj66zbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yMOqCRxI--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zn28zlp0cmrpqvj66zbn.png" alt="Screenshot example3"&gt;&lt;/a&gt;&lt;br&gt;
Therefore, the output shall be 22 because that is the index for the last "a" in the original string.&lt;/p&gt;

</description>
      <category>javascript</category>
    </item>
  </channel>
</rss>
