

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to execute a JavaScript function when I have its name as a string?
To execute a JavaScript function when its name is as a string, you can access class methods by name
Example
<html> <body> <script> class Demo { methodOne(){ document.write("50"); } methodTwo(){ this['methodOne'](); document.write("<br> 100"); } } let num = new Demo(); num['methodTwo'](); </script> </body> </html>
- Related Questions & Answers
- How to execute a JavaScript function using its name in a variable?
- How do I invoke a Java method when given the method name as a string?
- How to get a function name as a string in Python?
- How to invoke a JavaScript Function as a function?
- JavaScript function to accept a string and mirrors its alphabet
- How to get a variable name as a string in Python?
- How to get a variable name as a string in PHP?
- Can a method have the same name as the class?
- How to execute a Javascript function in Python with Selenium?
- How to invoke a JavaScript Function as a method?
- How do I execute a string containing Python code in Python?
- How do I trigger a function when the time reaches a specific time in JavaScript?
- How to stop a function during its execution in JavaScript?
- How can I parse a numeric string to its corresponding float value?
- How to load a JavaScript function using the variable name?
Advertisements