Reference sub-article Finding a substring inside a string and extracting it,
Paragraph 2, the below sub-part;
You could use this to find all instances of strings that don’t contain the substring ‘mozilla’, or do, if you use the negation operator, as shown below. You could do something like this:
if(browserType.indexOf('mozilla') !== -1) {
// do stuff with the string
}
While I understand the comparison operator Strict-non-equality !==
,
I’m having difficulty understanding the methodology of how this works with the -1
, as in the above example, and in the Active learning example: Filtering greeting messages exercise.
Could someone expound and explain this methodology in more detail please?
if (greetings[i].indexOf('Christmas') !== -1 )
Thank You! 
Ooh, that’s how that works…
,
explains much!
Thanks Chris!!
Spoiler Alert
Spoiler Alert 
I’m posting this to help other MDN students who might be working through this course behind me. So, don’t read this unless your truly stuck (such as I was
).
If so, you can go to my project version of this learning exercise;
Filtering Greeting Messages to see my notes and examples.
Also, here is a “story version” of the js which helped me to see how this works
(working version at the above linked site).
<section class="oneWayMission">
const volunteerRoster = document.querySelector('.oneWayMission ol');
volunteerRoster.innerHTML = '';
let reportToCommandCall = ['DigitalEngine',
'Wags',
'ChrisMills',
'Yo-Yo',
'Lt. Bot 000',
'Lt. Bot 001',
'Lt. Bot 002',
'Lt. Bot 003'];
for (let ibot = 0; ibot < reportToCommandCall.length; ibot++) {
let callForVoluteers = reportToCommandCall[ibot];
if (reportToCommandCall[ibot].indexOf('Lt. Bot') !== -1 ) {
let didNotStepBackFastEnough = callForVoluteers;
let missionRoster = document.createElement('li');
missionRoster.textContent = didNotStepBackFastEnough;
volunteerRoster.appendChild(missionRoster);
}
}