Tengo esta matriz de objeto:
let choices = [ {title: 'Single Card Payment', func: 'singleCard'}, {title: 'Monthly Card Payment', func: 'monthlyCard' }, {title: 'Monthly Direct Debit Payment', func: 'monthlyDD'} ]Lo estoy recorriendo y me gustaría llamar a funciones con el valor de la func, como esta (que obviamente es incorrecta)
for(choice for choices) { choice.func('some', 'params'); }Puede crear un objeto con métodos. Como abajo
const funcs = { singleCard: () => { console.log('single card called ')} }Y luego llamar así
for (i in choices) { funcs[choices[i].func]() }usando la funcion malvada :
let choices = [ {title: 'Single Card Payment', func: 'singleCard'}, {title: 'Monthly Card Payment', func: 'monthlyCard' }, {title: 'Monthly Direct Debit Payment', func: 'monthlyDD'} ] for(i in choices) { eval(choices[i].func)('some', 'params'); }editar: es eval chicos no malvados. 0K.