Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,885 questions

51,811 answers

573 users

How to use indexOf() to get the index within a String of the first occurrence of the specified value in JavaScript

3 Answers

0 votes
// str.indexOf(searchValue[, fromIndex])

var s = 'Online JavaScript Cloud Products';

document.write(s.indexOf('JavaScript') + "<br />"); // 7
document.write('PHP JavaScript'.indexOf('PHP') + "<br />"); // 0
document.write(s.indexOf('Online') + "<br />"); // 0
document.write(s.indexOf('Onlinee') + "<br />"); // -1
document.write(s.indexOf('JavaScript', 0) + "<br />"); // 7
document.write(s.indexOf('JavaScript', 7) + "<br />"); // 7
document.write(s.indexOf('', 1) + "<br />"); // 1
document.write(s.indexOf('', 7) + "<br />"); // 7
document.write(s.indexOf('', 130) + "<br />"); // 32
document.write(s.indexOf('', 280) + "<br />"); // 32


/*
run:

7
0
0
-1
7
7
1
7
32
32

*/

 



answered Aug 10, 2016 by avibootz
0 votes
// str.indexOf(searchValue[, fromIndex])

var s = 'Online JavaScript Cloud Products';

document.write(s.indexOf('JavaScript') + "<br />"); 
document.write(s.indexOf('JAVASCRIPT') + "<br />"); 



/*
run:

7
-1

*/

 



answered Aug 10, 2016 by avibootz
edited Aug 10, 2016 by avibootz
0 votes
// str.indexOf(searchValue[, fromIndex])

var s = 'Online JavaScript Cloud Products';

document.write(s.indexOf('JavaScript') + "<br />"); 
document.write(s.indexOf('JavaScrapt') + "<br />"); 



/*
run:

7
-1

*/

 



answered Aug 10, 2016 by avibootz
...