Horje
Index of an element Code Example
Index of an element
/*To search for the index of a substring or string within an array, 
use .indexOf() 
If you search for something that isn't there, the function will return -1*/

let mechs = ["madcat", "blood asp", "atlas"];
console.log(mechs.indexOf("madcat"); //returns 0
console.log(mechs.indexOf("atlas"); //returns 2

let clan = "nova cat";
console.log(clan.indexOf("a")); /*returns 3 (Only the first instance of the
character is used.*/
console.log(clan.indexOf("cat")); /*returns 5 (Finds the index of the beginning
character)*/
console.log(clan.indexOf("s")); //returns -1




Javascript

Related
airbnb react native eslint Code Example airbnb react native eslint Code Example
airbnb and eslint react native Code Example airbnb and eslint react native Code Example
angular how to iterate object Code Example angular how to iterate object Code Example
bootstrap aria-hidden Code Example bootstrap aria-hidden Code Example
mongoose sparse index Code Example mongoose sparse index Code Example

Type:
Code Example
Category:
Coding
Sub Category:
Code Example
Uploaded by:
Admin
Views:
7