From If/else to Array [duplicate]


i got this little problem: i want to switch from this (the firts one) to second one: ain’t wanna the first because is very ugly, so i prefet to make one array with slice function and put less code insede the index. I hope someone can help me 🙂
ps. Sorry for my bad english.

var mnct = Utility.getHOSTvalue("MN00-MNCT")

var arraymnct = ["311092","312092","311093","312093","311100","312100","311101","312101","311102","312102","311103","312103","311118","312043","311043","312044","311122",
"312119","311123","312120","311120","312117","311121","312118","311089","312089","311091","312091","311106","312106","311107","312107","311109","312109",
"311110","312110","311041","312041","311042","312042","311114","312113","311115","312114","311116","312115","311117","312116","311044","312045","311047",
"312047","311053","312053","311055","312055","311049","312049","311051","312051","311045","312046","311048","312048","311054","312054","311056","312056",
"311050","312050","311052","312052"];

if((mnct == "311092")||(mnct == "312092")||(mnct == "311093")||(mnct == "312093")||(mnct == "311100")||(mnct == "312100")||(mnct == "311101")||(mnct == "312101")||
(mnct == "311102")||(mnct == "312102")||(mnct == "311103")||(mnct == "312103")||(mnct == "311118")||(mnct == "312043")||(mnct == "311043")||(mnct == "312044")||
(mnct == "311122")||(mnct == "312119")||(mnct == "311123")||(mnct == "312120")||(mnct == "311120")||(mnct == "312117")||(mnct == "311121")||(mnct == "312118")||
(mnct == "311089")||(mnct == "312089")||(mnct == "311091")||(mnct == "312091")||(mnct == "311106")||(mnct == "312106")||(mnct == "311107")||(mnct == "312107")||
(mnct == "311109")||(mnct == "312109")||(mnct == "311110")||(mnct == "312110")||(mnct == "311041")||(mnct == "312041")||(mnct == "311042")||(mnct == "312042")||
(mnct == "311114")||(mnct == "312113")||(mnct == "311115")||(mnct == "312114")||(mnct == "311116")||(mnct == "312115")||(mnct == "311117")||(mnct == "312116")||
(mnct == "311044")||(mnct == "312045")||(mnct == "311047")||(mnct == "312047")||(mnct == "311053")||(mnct == "312053")||(mnct == "311055")||(mnct == "312055")||
(mnct == "311049")||(mnct == "312049")||(mnct == "311051")||(mnct == "312051")||(mnct == "311045")||(mnct == "312046")||(mnct == "311048")||(mnct == "312048")||
(mnct == "311054")||(mnct == "312054")||(mnct == "311056")||(mnct == "312056")||(mnct == "311050")||(mnct == "312050")||(mnct == "311052")||(mnct == "312052")) 
    this.presence = "hidden";
else
    this.presence = "visible";

I want something like this:

var mnct = Utility.getHOSTvalue("MN00-MNCT")

var arrayMnct = ["311092","312092","311093","312093","311100","312100","311101","312101","311102","312102","311103","312103","311118","312043","311043","312044","311122",
"312119","311123","312120","311120","312117","311121","312118","311089","312089","311091","312091","311106","312106","311107","312107","311109","312109",
"311110","312110","311041","312041","311042","312042","311114","312113","311115","312114","311116","312115","311117","312116","311044","312045","311047",
"312047","311053","312053","311055","312055","311049","312049","311051","312051","311045","312046","311048","312048","311054","312054","311056","312056",
"311050","312050","311052","312052"];

var breakArray = arrayMnct.slice();

if(mnct == breakArray)  
    this.presence = "hidden";
else
    this.presence = "visible";

Source: JavaSript – Stack Overflow

November 11, 2021
Category : News
Tags: arrays | if-statement | javascript

Leave a Reply

Your email address will not be published. Required fields are marked *

Sitemap | Terms | Privacy | Cookies | Advertising

Senior Software Developer

Creator of @LzoMedia I am a backend software developer based in London who likes beautiful code and has an adherence to standards & love's open-source.