'Array of functions with condition

I am currently working on an array of functions and want to get the right function back with a condition.

Here is my code :

  {'key':'a', 'function':func_a},
  {'key':'b', 'function':func_b},
  {'key':'c', 'function':func_c},
  {'key':'d', 'function':func_d}
];

const term = 'b';

const funcToDo = for (var i = 0; i < array.length; i++) {
    if (term === a[i].key) {
      return a[i].function
    }
  }

const shouldIDoIt = true;
shouldIDoIt === true ? functToDo() : null;

Can someone help me on this ?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source