mardi 26 mars 2019

checking if condition matchers any value of an array in Javascript

What would be the best way to check if a condition matches any value in array?

So for example I want to implement a retry logic if there is a 5xx error received.

  var searchUserRequest = httpClient.request(searchUserRequestOptions, (res => {
    if(res.statusCode ===  500 || res.statusCode ===  501 res.statusCode ===  502) {
      process.stdout.write('HELLO!!!!!! ');

      }

  }));

ideally I would like to put all the 5xx error does in a list or an array and then check if the res.status code equals any of the 5xx error codes.

What is the best way to do this in Javascript? Can I do this without a loop?

Aucun commentaire:

Enregistrer un commentaire