Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

search string for character javascript

/*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 :: input events 
Javascript :: password validation in regex 
Javascript :: remove specific item from array 
Javascript :: js push method 
Javascript :: redirect to website from promise value fetch 
Javascript :: us postal code regex 
Javascript :: JS how to determine if page was cached 
Javascript :: length of list in javascript 
Javascript :: javascript max 
Javascript :: mongoose number bigger 
Javascript :: typeof javascript 
Javascript :: javascript sort a b 
Javascript :: express octet stream 
Javascript :: creating react app using npx 
Javascript :: find average of numbers 
Javascript :: ajouter javascript dans html 
Javascript :: pm2 logs on same console 
Javascript :: create empty json file python 
Javascript :: update angular project 
Javascript :: javascript array contains 
Javascript :: javascript get next 15min 
Javascript :: getattribute javascript 
Javascript :: navlink activestyle not working 
Javascript :: let var 
Javascript :: Uncaught (in promise) cancel 
Javascript :: split and join in node js 
Javascript :: get user agent in js 
Javascript :: why we need react js 
Javascript :: vuejs transform observer to object 
Javascript :: uncheck multiple checkboxes javascript 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =