0

I have the following script:

var argv = process.argv.splice(2);
var obj = argv[0];
var pkg = require("./package.json");

console.log(pkg.obj);

I want my script to parse for whatever obj equals, not obj itself. Is there any way to do this?

3
  • 1
    I don't understand your question, but are you looking for pgk[obj] maybe? Commented Jul 23, 2016 at 15:22
  • @mmm that solved it! Thanks so much! Feel free to answer the question with that, and I'll accept. Commented Jul 23, 2016 at 15:45
  • @mmm awesome! I accepted, again, thanks so much! Commented Jul 23, 2016 at 15:53

1 Answer 1

3

To do what you want, you can use bracket notation:

console.log(pkg[obj]);
Sign up to request clarification or add additional context in comments.

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.