0

I want to do something like this.

var abc = require('./index')
var x = "someModule";
abc.x.someFunction();

So basically I want to do something like this:

abc.someModule.someFunction();

How do I achieve this?

2

2 Answers 2

1

Use bracket notation

Something like

var x = "someModule";
abc[x].someFunction();
Sign up to request clarification or add additional context in comments.

Comments

0

This should work:

var abc = require('./index')
var x = "someModule";
abc.[x].someFunction();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.