Javascript dynamically invoke object method from string

Solution 1:

if the name of the property is stored in a variable, use []

foo[method]();

Solution 2:

Properties of objects can be accessed through the array notation:

var method = "smile";
foo[method](); // will execute the method "smile"

Solution 3:

When we call a function inside an object, we need provide the name of the function as a String.

var obj = {talk: function(){ console.log('Hi') }};

obj['talk'](); //prints "Hi"
obj[talk]()// Does not work