# what is indexOf() in Javascript ?



## changintimes (Sep 4, 2004)

i am just learning javascript and i am having trouble understanding the indexOf() code, 

can anybody help me with this ?

thanks very much, 

changintimes


----------



## RickPlmr (Aug 26, 2006)

This is a very handy function that lets you determine the location of a character or string within another string. For example, let's say you were trying to determine the identity of a visitor to your website (assuming you had set up some sort of user sign in that returned a querystring variable called visitor_id). 

// Here's the first string:
var url="http://www.yourwebsite.com/login.php?visitor_id=1234";

// Now let's see if visitor_id=1234 is located in that string:
var blacklisted_visitor = url.indexOf("visitor_id=1234");

// If it was found, then prompt the user
if (blacklisted_visitor != -1) {
alert('You are not allowed to use this website');
}

Does that make sense?


----------



## changintimes (Sep 4, 2004)

thanks very much for the response RickPlmr, a bit involved for me though as i am a beginner,

here is the source code from the javascript book that i am learning from..............

http://www.javascriptworld.com/scripts/script03.02.html

i basically understand the entire code except for this part..............

name.indexOf("QuickTime") >= 0)

i don't understand the function of "name" and "indexOf",

why does this sometimes return -1 and other times return 0 ?


----------



## brendandonhu (Jul 8, 2002)

"name" is the string its searching in. If it returns 0, that means the string starts with "QuickTime". If it returns -1, the string doesn't contain "QuickTime" at all.


----------



## changintimes (Sep 4, 2004)

thanks Brendan,

i am starting to understand,

but could it have been written like this ? ...............

............i put the _ after name instead of plugins,_


----------



## brendandonhu (Jul 8, 2002)

No, plugins is an array and plugins_.name is the name of the current plugin._


----------



## changintimes (Sep 4, 2004)

okay i think i'm catching on, 

anybody know of a good website (not necessarilly a tutorial) that i can play with the javascript codes in, codes that are very simple for a beginner ? 

if i became very good at javascipt, would it be possible to make some money as a js developer ? i'm sensing the real money is basically in web development though,


----------



## brendandonhu (Jul 8, 2002)

http://javascriptsource.com


----------



## changintimes (Sep 4, 2004)

thanks brendan, i'm getting into some button js codes at that website right now, seems very good for me as a beginer,


----------

