Having trouble, am i using .indexOf() correctly?

I’m trying to get comfortable with all the array methods. Why doesn’t this code work? I’ve tried without === true, !com[i].indexOf(), and tried putting conditionals in an else if statement.

let str = ['a', 'z'];
let com = 'abcdefgh'

for(let i = 0; i < com.length; i++) {
    if(com[i].indexOf(str) === true) {

    else {

It’s because indexOf() returns an integer (the index) and you are strict-comparing it to a boolean. Strict equality operator compares both value and type. You could use the normal equality operator (==) but keep in mind that 0 is a “falsy” value and so if the index is 0 it will return false.

let str = "Hello world";
let comp = 'zyxHgo'

for(let i = 0; i < str.length; i++){
    if(comp.indexOf(str[i]) !== -1) 

    else {

Got it figured out, thanks for the help!

hello camper ,I think you want check if a particular letter is existed in the array so then you will log in the console a boolean true ,and you want to check that ,by looping throung every letter in the com wich is a string ,but before that rename str to arr , because it’s actually an array .
if you want to check if a letter is there in an array the mehod is like this
arr.indexOf(here put what are you serching for)
and also index of method does not return true or false ,beacause if it finds what it is looking for it retuns a number ,if not it retuns -1
so you have to change the boolean you are using to != -1 wich means that it found some thing .

I thought you had to turn it into an array first as well, but apparently there is no need for that, this method works on a string type.