0

I trying to get all keys and use them to access values of that keys, depends of user...

i have this code:

var fs = require('fs');
var _ = require('underscore');
var obj = JSON.parse(fs.readFileSync('ENG.json', 'utf8'));
var lang = process.argv.slice(2);
var keys = _.keys(obj);
console.log(obj.keys[0].text1);

Help me please.

2
  • I don't see a question here. Commented Jun 29, 2017 at 9:27
  • I need get a values using keys variable Commented Jun 29, 2017 at 9:28

1 Answer 1

1

You mean this way?

keys.forEach(key => {
  console.log(obj[key]);
});

By the way, no need for underscore. Use Object.keys(obj).

And you can easily require your json this way:

// most probably './ENG.json';
const obj = require('ENG.json');
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.