please if you could give me more detail of why the return of each exercise:
"Blue Whale".indexOf("Whale",0) // returns 5
"Blue Whale".indexOf("Whale",5) // returns 5
"Blue Whale".indexOf("",9) // returns 9
Thank you.
please if you could give me more detail of why the return of each exercise:
"Blue Whale".indexOf("Whale",0) // returns 5
"Blue Whale".indexOf("Whale",5) // returns 5
"Blue Whale".indexOf("",9) // returns 9
Thank you.
The
indexOf
method reads everything as a position is number, space in white or string of text
Here the example with each of the scenarios proposed in the question
let phrase = 'Blue Whale'
console.log(phrase.indexOf("Whale", 0))
console.log(phrase.indexOf("Whale", 5))
console.log(phrase.indexOf("", 9))
the indexOf()
method when reading the text text as an array; it's as if I saw it in the following way
B L U E W H A L E => CADENA DE TEXTO
0 1 2 3 4 5 6 7 8 9 => POSICIÓN DENTRO DEL ARRAY DE CADA ELEMENTO