When you want to search inside one string for another string, JavaScript gives us two great methods – indexOf and lastIndexOf.
Code GIST:
Tag: lastindexof javascript, MAD9014,MAD9022,JavaScript,JS,Strings,String methods,indexOf,lastIndexOf,searching for strings,search string
Xem Thêm Bài Viết Về Công Nghệ Tại Đây: https://tipcongnghe.net/cong-nghe
Nguồn: https://tipcongnghe.net
Entendi como usarlo aunque esta en ingles el audio
Can someone explain this?
let x = ["Python", "C++", "C", "Java"];
let z = x.lastIndexOf("C", 1);
and its -1…. How??
Thank you very much man!
can u plz tell me how the second parameter starts to look for the specified words when it comes down to lastIndexOf("string", 15) for instance?
AS THE STRINGS ARE PRIMITIVE WHY DO THEY POSSESS METHODS?
CAN WE GET A VIDEO MADE ON THIS BY YOU SIR?
your very Good at explaining
Your video is amazing ♥ . Thank you so much for taking the time to make this helpfull explanation
Why would you store console.log() in a variable?
We can always learn something new and special from you, the last indexOf example is excellent. Thank you.
i believe a common use of the `Start Position` parameter is to find successive instances of the same item:
L=console.log
{
const sSentence = 'Be the change that you want to see.'
const sChar = 'e'
let aFound = FindItems(sSentence, sChar)
L(aFound)
function FindItems(sSentence, sChar)
{
let iFound, iStart, aFound = []
do
{
iFound = sSentence.indexOf(sChar, iStart)
if (iFound > -1) {
aFound.push(iFound)
iStart = iFound + 1
}
}
while (iFound > -1)
return aFound
}
}
But, would array.Filter be faster than this?
i realized in JS, both negative and positive numbers are truthy, and 0 is falsey. I can understand why indexOf returns -1 for not-found. It can't return 0, cuz that's a legitimate array-index.
Still, it seems somehow inappropriate for indexOf to return -1, since it's a nonsensical array-index, and -1 is truthy. Wondering if there's another value that would be more appropriate, like null, or undefined, or false?
Thank you! Excellent presentation!
helpfull explanation .. thanks alot
Thanks you. All is clear)
Very nice explanation but please improve sound quality. It's very low