var a=1,b=2,c=3,d=4; const rules = [ { match: function (a, b, c,d) { return a;}, action: function (a, b, c,d) { console.log(a) } }, { match: function ( a, b, c,d) { return b; }, action: function (a, b, c,d) { console.log(b) } }, { match: function (a, b, c,d) { return c; }, action: function (a, b, c,d) { console.log(c) } }, { match: function (a, b, c,d) { return d;}, action: function (a, b, c,d) {console.log(d) } } ] function demo (a, b, c,d) { for (let i = 0; i < rules.length; i++) { if (rules[i].match(a, b, c,d)==2) { return rules[i].action(a, b, c) } } } demo (a, b, c,d)