Sometimes, we want to dynamically invoke object method from string with JavaScript.
In this article, we’ll look at how to dynamically invoke object method from string with JavaScript.
How to dynamically invoke object method from string with JavaScript?
To dynamically invoke object method from string with JavaScript, we use square brackets.
For instance, we write
foo[method]();
to call the method
method in foo
.
method
is a string with the method name of the method in the foo
object.
Conclusion
To dynamically invoke object method from string with JavaScript, we use square brackets.