Is there a shortcut for the following -
if(tld == "com" || tld == "net" || tld == "co" || tld == "org" || tld == "info" || tld == "biz") { //do something; }
you can use an array
if(["","com","net","co","org","info","biz"].indexOf(tld) > -1) { // do something }
or if you use jquery:
$.inArray(tld, ["com","net","co","org","info","biz"])
REF - Operation Performance OR (||) vs inArray ()
Use regex:
if ( /^(com|net|co|org|info|biz)$/i.test(tld) ) { // do something }
Have you considered using the switch statement? something like that:
switch(tld) { case 'com': case 'net': case 'co': ... ... // do something for all of them break; default: // if you want you can have default process here break; }
Source: https://habr.com/ru/post/918596/More articles:How to use the same SQLite3 database from multiple Perl processes? - perldecoding json string in python - jsonA few questions regarding the listener HL7 - c #How to resize / resize a window using python-xlib? - pythonRails 3 polymorphic_path - how to change the default route_key - ruby-on-rails-3How to remove a subset of a 2d array? - pythonHow can I customize an HTML page for mobile users? - htmlInstall mod_perl-2.0.7 on Apache httpd-2.4.2 - perlAcord standard for insurance. Has anyone dealt with this disorder? - c #How can we imagine hierarchies of deep models in Backbone.js - backbone.jsAll Articles