Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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
Comment

PREVIOUS NEXT
Code Example
Javascript :: get index in map javascript 
Javascript :: JavaScript .clearRect 
Javascript :: remove item from array javascript 
Javascript :: check user login or not in Shopify 
Javascript :: javascript equivalent of CTRL+F5 
Javascript :: exit foreach loop js 
Javascript :: angular conditionally show tooltip 
Javascript :: angular radio box already showing checked 
Javascript :: biggest number javascript 
Javascript :: form validation jquery input array 
Javascript :: what is side effect 
Javascript :: sort array by date in javascript 
Javascript :: check fpr multiple values in an array jquery 
Javascript :: using regex in javascript 
Javascript :: average of numbers 
Javascript :: save networkx graph to json 
Javascript :: How to globally use Axios instance and interceptors in Vue.js 
Javascript :: http header express 
Javascript :: dropzone add download button addedfile 
Javascript :: react router how to send data 
Javascript :: javascript date get next 15 minutes 
Javascript :: js add to map 
Javascript :: javascript convert timezone name to abbreviation 
Javascript :: let var diferencia 
Javascript :: recieve voice channel audio discord.js 
Javascript :: fetch api 
Javascript :: two digits number javascript 
Javascript :: clear all cookies 
Javascript :: javascript function to strikethrough text 
Javascript :: mongoose make array required 
ADD CONTENT
Topic
Content
Source link
Name
2+5 =