Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Test string with a string list

I have a list of Id contained in an array :

var listId: string[] = [];
var newId: boolean;
for (let i in data.chunk) {
    listId.push(data.chunk[i].aliases[0]);
}

I then want to test my new Id with this whole list. If my new Id is in the list I want to return a false, and if it is not returned a true.

for(let i of listId) {
    if(member.userId !== listId[i]) {
      newid = true;
    }
    else {
      newId = false;
    }
  }

I do not see how to do it .. My proposed solution does not work

like image 319
Floriane Avatar asked Dec 18 '25 06:12

Floriane


1 Answers

Try this

    if(listId.indexOf(member.userId) !== -1)
     {
      newId = false; 
     }else
      {
       newid = true;
      }
like image 58
ganesh Avatar answered Dec 19 '25 18:12

ganesh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!