czlsws
0
Q:

js indexof string


var str = "HELLO WORLD";

var res = str.charAt(0); 
2
//indexOf getting index of array element, returns -1 if not found
var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found
var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9
30
//indexOf - JS method to get index of array element. 
// Returns -1 if not found

var colors=["red","green","blue"];
var pos=colors.indexOf("blue");//2

//indexOf getting index of sub string, returns -1 if not found

var str = "We got a poop cleanup on isle 4.";
var strPos = str.indexOf("poop");//9

//Eg with material ui

<Checkbox
   checked={value.indexOf(option) > -1}
   value={option}
/>
14
const paragraph = 'The quick brown fox';

console.log(paragraph.indexOf('T'));
>> 0

console.log(paragraph.indexOf('h'));
>> 1

console.log(paragraph.indexOf('Th'));
>> 0

console.log(paragraph.indexOf('he'));
>> 1

console.log(paragraph.indexOf('x'));
>> 18
2
let monTableau = ['un', 'deux','trois', 'quatre'] ;
console.log(monTableau.indexOf('trois')) ;
 
2
"Blue Whale".indexOf("Blue");     // retorna  0
"Blue Whale".indexOf("Blute");    // retorna -1
"Blue Whale".indexOf("Whale", 0); // retorna  5
"Blue Whale".indexOf("Whale", 5); // retorna  5
"Blue Whale".indexOf("Whale", 7); // retorna -1
"Blue Whale".indexOf("");         // retorna  0
"Blue Whale".indexOf("", 9);      // retorna  9
"Blue Whale".indexOf("", 10);     // retorna 10
"Blue Whale".indexOf("", 11);     // retorna 10
1
str.indexOf(searchValue[, fromIndex])
0
String1.indexOf(index2); 
0

New to Communities?

Join the community