[Solved] Javascript pass function in object value [closed]


If you want buttonFunc to be a function, then do not enclose it in quotation marks, because that makes it a string and not a function:

buttonFunc: '() => console.log("test")',

should be

buttonFunc: () => console.log('test'),

Then you can execute it like so:

myArray.forEach(element => {
    element.buttonFunc();
});
// should console.log('test')

solved Javascript pass function in object value [closed]