How can js if multiple judgments be optimized to the simplest?

often need to convert a value after encountering a circular array

let arr = res.data.orderinformation;
for (let i = 0; i < arr.length; iPP) {
  if (arr[i].ctype == "11001") {
    arr[i].ctype = "";
  } else if (arr[i].ctype == "11008") {
    arr[i].ctype = "";
  } else if (arr[i].ctype == "11011") {
    arr[i].ctype = "";
  } else if (arr[i].ctype == "11012") {
    arr[i].ctype = "";
  } else if (arr[i].ctype == "11013") {
    arr[i].ctype = "";
  } else if (arr[i].ctype == "11014") {
    arr[i].ctype = "";
  }

  // switch, , ?
  //   switch (arr[i].ctype) {
  //     case "11001":
  //     arr[i].ctype = "";
  //     break;
  //     case "11008":
  //     arr[i].ctype = "";
  //     break;
  //     case "11011":
  //     arr[i].ctype = "";
  //     break;
  //     case "11012":
  //     arr[i].ctype = "";
  //     break;
  //     case "11013":
  //     arr[i].ctype = "";
  //     break;
  //     case "11014":
  //     arr[i].ctype = "";
  //     break;
  //     default:
  //     break;
  //   } 

  // 
  arr[i].ctime = new Date(arr[i].ctime);
  arr[i].ctime =
    arr[i].ctime.toLocaleDateString().replace(/\//g, "-") +
    " " +
    arr[i].ctime.toTimeString().substr(0, 8);
}
Dec.03,2021

const d = {
  '11001': '',
  '11008': '',
  '11011': '',
  '11012': '',
  '11013': '',
  '11014': '',
};
for (let i = 0; i < arr.length; iPP) {
  if (d[arr[i].ctype]) arr[i].ctype = d[arr[i].ctype];
}

the, switch case statement in js uses congruence
Please confirm whether arr [I] .ctype is the string "11001" or the number 11001 .


case is actually =, which is different from =. 2 = "2" holds, but 2 = "2" does not hold because they are of different types. In addition, a better way to simplify is to use the upstairs, predefined key value pair object, and then match its key.

Menu