{"id":12574,"date":"2020-05-08T14:23:56","date_gmt":"2020-05-08T21:23:56","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12574"},"modified":"2023-12-01T02:44:55","modified_gmt":"2023-12-01T10:44:55","slug":"javascript-indexof","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/","title":{"rendered":"JavaScript indexOf: A Step-By-Step Guide"},"content":{"rendered":"\n<p><em>The JavaScript indexOf() method returns the position of an item in a list or a substring in a string. The indexOf() JavaScript method returns -1 if a specified value does not appear in a list or string. Only the index value of the first occurrence of a value is returned.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator has-css-opacity\"\/>\n\n\n\n<p>Often, you may want to find out whether the string or array contains a particular value. For example, you may have a list of donut flavors sold in your donut store. You may want to check whether you removed the unpopular triple-chocolate donut from the menu.<\/p>\n\n\n\n<p>That\u2019s where the <em>indexOf()<\/em> JavaScript method comes in handy. The <em>indexOf() method<\/em> returns the first index at which a certain value can be found in an array or a string. If a value is not found, a special -1 value is returned.<\/p>\n\n\n\n<p>In this tutorial, we are going to explore the basics of the <em>indexOf()<\/em> method in JavaScript. We\u2019ll go through two examples to show this method in action to help build your understanding of the indexOf() method.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JavaScript indexOf() with Arrays<\/h2>\n\n\n\n<p>The <em>Array.indexOf()<\/em> <a href=\"https:\/\/careerkarma.com\/blog\/how-to-use-javascript-functions\/\">built-in method<\/a> searches through an array for a value. The method finds the index value of the first time a specified item appears in an array. If a specified item is found, the <em>indexOf()<\/em> method returns the index number of the first occurrence of the value. If the specified item is not found, <em>indexOf()<\/em> will return <em>-1<\/em>.<\/p>\n\n\n\n<p>The <em>indexOf()<\/em> method is case-sensitive. This means indexOf() will return -1 if a value appears in a list with a different case than we have specified.<\/p>\n\n\n\n<p>Here\u2019s the syntax for the <em>indexOf()<\/em> method in JavaScript:<\/p>\n\n\n\n<p>The <code>indexOf()<\/code> method is case sensitive. Here\u2019s the syntax for the <code>indexOf()<\/code> function in JavaScript:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>array_name.indexOf(item, start_position);<\/pre><\/div>\n\n\n\n<p>The <em>item<\/em> parameter is the item for which we are searching in our <a href=\"https:\/\/careerkarma.com\/blog\/javascript-array\/\">JavaScript array<\/a>. This parameter is required. The <em>start_position<\/em> parameter is optional. <em>start_position<\/em> is the position in our array at which indexOf() begins searching.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">An Example Scenario<\/h3>\n\n\n\n<p>Let\u2019s say that we have run out of cinnamon. We want to check if cinnamon donuts are still listed on our shop\u2019s menu. If donuts are on the menu, we will remove them. We could use the following code to perform this action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var donut_flavors = ['Jam', 'Blueberry', 'Cinnamon', 'Apple Crumble', 'Frosted'];\nconsole.log(donut_flavors.indexOf('Cinnamon'));<\/pre><\/div>\n\n\n\n<p>The indexOf method returns: 2. As you can see, <code>Cinnamon<\/code> is present in our array. So, our code has returned the index value of the first instance of <code>Cinnamon<\/code> in our array, which in this case is <code>2<\/code>.<br><\/p>\n\n\n\n<p>The indexOf method returns: 2. As you can see, <em>Cinnamon<\/em> is present in our array. So, our code has returned the index value of the first instance of <em>Cinnamon<\/em> in our array, which in this case is <em>2<\/em>.<\/p>\n\n\n\n<p>Our program would return 2 even if our array contained multiple instances of <em>Cinnamon<\/em>. This is because <em>indexOf()<\/em> only returns the index position of the first instance of an item.<\/p>\n\n\n\n<p>Let\u2019s say that our chef has invented a new <em>Jam Supreme<\/em> donut and added it to our <em>donut_flavors<\/em> array. However, she is unsure whether she called the donut <em>Jam<\/em> or <em>Jam Supreme.<\/em> She wants to check so that the menu is accurate.<\/p>\n\n\n\n<p>Because <em>Jam<\/em> is already first in the array, <em>indexOf()<\/em> will return the position of <em>Jam.<\/em> However, if we use the <em>start_position<\/em> parameter, we can skip over the first position and run our search. Here\u2019s the code our chef could use to check whether <em>Jam<\/em> appears after the index position <em>1<\/em> in the array:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var donut_flavors = ['Jam', 'Blueberry', 'Cinnamon', 'Apple Crumble', 'Frosted', 'Jam Supreme'];\nconsole.log(donut_flavors.indexOf('Jam', 1));<\/pre><\/div>\n\n\n\n<p>Our code returns: <em>-1.<\/em> While <em>Jam<\/em> does exist in our array, it comes before the index value <em>1.<\/em> The value <em>Jam<\/em> does not exist in the area through which we are searching.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">JavaScript indexOf() with Strings<\/h2>\n\n\n\n<p><em>indexOf()<\/em> can be used to find a <a href=\"https:\/\/careerkarma.com\/blog\/how-to-use-substring-in-javascript\/\">substring within a string<\/a>. The string indexOf() method returns the index number at which a substring starts in another string.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">String Refresher<\/h3>\n\n\n\n<p>Like arrays, strings in JavaScript also have their own index values. Strings are indexed from left to right, starting at the index value <code>0<\/code>. So, for our above example string, the following index values would be assigned:<\/p>\n\n\n\n<figure class=\"wp-block-table course-info-table\"><table><tbody><tr><td>E<\/td><td>x<\/td><td>a<\/td><td>m<\/td><td>p<\/td><td>l<\/td><td>e<\/td><td>!<\/td><\/tr><tr><td>0<\/td><td>1<\/td><td>2<\/td><td>3<\/td><td>4<\/td><td>5<\/td><td>6<\/td><td>6<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>So, if we wanted to get the character at the index position <code>4<\/code>, we could do so using the following code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>console.log(example_string[4]):<\/pre><\/div>\n\n\n\n<p>Our code returns: <code>p<\/code>.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">String.indexOf()<\/h3>\n\n\n\n<p>The <em>String.indexOf()<\/em> method can be used to check if a string contains a particular substring. If the substring can be found in the string, <em>indexOf()<\/em> will return the index position of the occurrence of the letter or string; if the substring cannot be found, <em>indexOf()<\/em> will return <em>-1.<\/em><\/p>\n\n\n\n<p>The <em>String.indexOf()<\/em> method uses the same syntax as the <em>Array.indexOf()<\/em> method:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>string_name.indexOf(substring, start_position)<\/pre><\/div>\n\n\n\n<p>We must specify a <em>substring<\/em> argument. This is the value for which we want to search in our string. The <em>start_position<\/em> argument is optional and tells the program to start the search at a specific index. The <em>start_position<\/em> argument defaults to index <em>0.<\/em><\/p>\n\n\n\n<p>Let\u2019s say that we have a string with our donut names, and we want to check if that string contains <em>Blueberry<\/em>. We could use the following code to perform this action:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var donut_flavors = 'Jam Blueberry Cinnamon Apple Crumble Frosted';\nconsole.log(donut_flavors.indexOf('Blueberry'));<\/pre><\/div>\n\n\n\n<p>Our code returns: 4. As you can see, our <code>donut_flavors<\/code> string contains <code>Blueberry<\/code> and substring starts at the index position <code>4.<\/code><br><\/p>\n\n\n\n<p>Our code returns: 4. As you can see, our <em>donut_flavors<\/em> string contains <em>Blueberry<\/em> and substring starts at the index position <em>4.<\/em><\/p>\n\n\n\n<p>But what if we wanted to check whether our <em>donut_flavors<\/em> string contained <em>Blueberry<\/em> after a specific index position? That\u2019s where the <em>start_position<\/em> argument comes in.<\/p>\n\n\n\n<p>Let&#8217;s search for the term <em>Blueberry<\/em> in our list. We shall begin our search at the index position 10 in our list:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var donut_flavors = 'Jam Blueberry Cinnamon Apple Crumble Frosted';\nconsole.log(donut_flavors.indexOf('Blueberry', 10));<\/pre><\/div>\n\n\n\n<p>Our code returns: <em>-1<\/em>. While <em>\u201cdonut_flavors\u201d<\/em> does include <em>\u201cBlueberry,\u201d<\/em> the string starts before the index value <em>10<\/em> in the array. Our code returns <em>\u201c-1\u201d.<\/em> This denotes that the substring could not be found.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Check if a Value Exists Using indexOf()<\/h2>\n\n\n\n<p>You can use an <a href=\"https:\/\/careerkarma.com\/blog\/javascript-if-else\/\">&#8220;if&#8221; statement<\/a> with the indexOf() method to check if a value exists in a string or an array. For example, you could use <em>indexOf()<\/em> to check if the donut menu contains a particular value. Then, you could print a message to the console if that value is found.<\/p>\n\n\n\n<p>Let&#8217;s write a program that prints a message to the console if &#8220;Chocolate&#8221; is found in a list of donuts. Here is our code:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>var donut_flavors = ['Jam', 'Blueberry', 'Chocolate', 'Cinnamon', 'Apple Crumble', 'Frosted'];\nif (donut_flavors.indexOf(\"Chocolate\") !== -1) {\n\tconsole.log(\"Chocolate donuts are on the menu!\");\n}<\/pre><\/div>\n\n\n\n<p>Our code returns:<code> \u201cChocolate donuts are on the menu!\u201d.<\/code><br><\/p>\n\n\n\n<p>On the first line of our code, we declare our array of donut flavors called <em>\u201cdonut_flavors,\u201d<\/em> which contains six values.<\/p>\n\n\n\n<p>Then, we create an if statement that uses indexOf to check if <em>\u201cdonut_flavors\u201d<\/em> contains <em>\u201cChocolate.\u201d<\/em> This if statement evaluates whether indexOf returns a value equal to <em>\u201c-1.\u201d<\/em><\/p>\n\n\n\n<p>If indexOf returns <em>\u201c-1,\u201d<\/em> it means our value could not be found in the array. This means our if statement will not execute. If indexOf returns any other value, our if statement will execute.<\/p>\n\n\n\n<p>In this case, indexOf() would return <em>2.<\/em> This is because <em>\u201cChocolate\u201d<\/em> is present in our <em>\u201cdonut_flavors\u201d<\/em> array. Our program prints out <em>\u201cChocolate donuts are on the menu!\u201d<\/em> because indexOf has returned a value that is not equal to -1.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The JavaScript <em>indexOf()<\/em> method checks whether a string or an array contains a particular value. The method returns the index number at which that value is found in the string or array. If the specified value is not found, <em>indexOf()<\/em> returns <em>\u201c-1.\u201d<\/em><\/p>\n\n\n\n<p>In this tutorial, we discussed the basics of arrays, strings, and how they are indexed. Then, we explored how to use the <em>indexOf()<\/em> method with both strings and arrays to check whether they contained a specific value.<\/p>\n\n\n\n<p>We discussed how to use the <em>indexOf()<\/em> method and an &#8220;if&#8221; statement to check if a value exists in a list or string.<\/p>\n","protected":false},"excerpt":{"rendered":"The JavaScript indexOf() method returns the position of an item in a list or a substring in a string. The indexOf() JavaScript method returns -1 if a specified value does not appear in a list or string. Only the index value of the first occurrence of a value is returned. Often, you may want to&hellip;","protected":false},"author":240,"featured_media":11168,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[11933],"tags":[],"class_list":{"0":"post-12574","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-javascript"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"JavaScript","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":"","is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JavaScript indexOf: A Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The JavaScript indexOf method allows programmers to find out whether a string or array contains a value, and returns the index number at which that value starts. Learn about how to use the indexOf method on Career Karma.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JavaScript indexOf: A Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"The JavaScript indexOf method allows programmers to find out whether a string or array contains a value, and returns the index number at which that value starts. Learn about how to use the indexOf method on Career Karma.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-05-08T21:23:56+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T10:44:55+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"668\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"JavaScript indexOf: A Step-By-Step Guide\",\"datePublished\":\"2020-05-08T21:23:56+00:00\",\"dateModified\":\"2023-12-01T10:44:55+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\"},\"wordCount\":1280,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg\",\"articleSection\":[\"JavaScript\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\",\"name\":\"JavaScript indexOf: A Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg\",\"datePublished\":\"2020-05-08T21:23:56+00:00\",\"dateModified\":\"2023-12-01T10:44:55+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The JavaScript indexOf method allows programmers to find out whether a string or array contains a value, and returns the index number at which that value starts. Learn about how to use the indexOf method on Career Karma.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg\",\"width\":1000,\"height\":668},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"JavaScript\",\"item\":\"https:\/\/careerkarma.com\/blog\/javascript\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"JavaScript indexOf: A Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JavaScript indexOf: A Step-By-Step Guide | Career Karma","description":"The JavaScript indexOf method allows programmers to find out whether a string or array contains a value, and returns the index number at which that value starts. Learn about how to use the indexOf method on Career Karma.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/","og_locale":"en_US","og_type":"article","og_title":"JavaScript indexOf: A Step-By-Step Guide","og_description":"The JavaScript indexOf method allows programmers to find out whether a string or array contains a value, and returns the index number at which that value starts. Learn about how to use the indexOf method on Career Karma.","og_url":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-05-08T21:23:56+00:00","article_modified_time":"2023-12-01T10:44:55+00:00","og_image":[{"width":1000,"height":668,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"6 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"JavaScript indexOf: A Step-By-Step Guide","datePublished":"2020-05-08T21:23:56+00:00","dateModified":"2023-12-01T10:44:55+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/"},"wordCount":1280,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg","articleSection":["JavaScript"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/javascript-indexof\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/","url":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/","name":"JavaScript indexOf: A Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg","datePublished":"2020-05-08T21:23:56+00:00","dateModified":"2023-12-01T10:44:55+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The JavaScript indexOf method allows programmers to find out whether a string or array contains a value, and returns the index number at which that value starts. Learn about how to use the indexOf method on Career Karma.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/javascript-indexof\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/photography-of-person-typing-1181675.jpg","width":1000,"height":668},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/javascript-indexof\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"JavaScript","item":"https:\/\/careerkarma.com\/blog\/javascript\/"},{"@type":"ListItem","position":3,"name":"JavaScript indexOf: A Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12574"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12574\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/11168"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}