0

I am trying to get the value of a key in a JSON object, and the name of the key is in a variable.

var fs = require('fs');

var id = 230345038039;
var jsonstuff = 
var parsedstuff = JSON.parse(fs.readFileSync('./file.json', 'utf8'));
console.log(parsedstuff.id);

Expected output: 12

I've tried parsedstuff.$$id, parsedstuff.${!id} and parsedstuff.$id. None work.

Is there a way to do this?

Edit: SOLVED. parsedstuff[id] is what I should be using.

MegaBatchGames
  • 125
  • 1
  • 7

0 Answers0