Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

multiple check if statement

hello so what I am trying to do is to check if selectedItem.status is any of these numbers I don’t want react do move on into the next blocks.

I have tried to do this another way like for example

 if(selectedItem.status !== ["16", "0", "12", "9", "11", "13", "17", "22"].indexOf(selectedItem.status))

but it didn’t work either

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

    if (
      selectedItem.status !== "16" ||
      "0" || 
      "12" ||
      "9" ||
      "11" ||
      "13" ||
      "17" ||
      "22"
    ) {
      if (!showErrorPage) {
        setShowErrorPage(true);
      }
      if (selectedFile && selectedItem["id"] === selectedFile["id"]) {
        errorCloseHandler();
        setClickedStatusId(0);
        return;
      }
      setSelectedFile(selectedItem);
      setClickedStatusId(selectedItem.id);

      if (!showErrorPage) {
        setHeadCells(
          originalHeaderColumns.map((h) => {
            h.hidden =
              h.id !== "userLogin" && h.id !== "fileName" && h.id !== "status";
            return h;
          })
        );
      } else {
        setHeadCells(originalHeaderColumns);
      }
    } else {
      return;
    }

>Solution :

You can use the array includes method. It will also check for element if it exists in the array and based on that you can apply your logic.

if(["16", "0", "12", "9", "11", "13", "17", "22"].includes(selectedItem.status)){
 // your code here.
}

This should work here.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading