Reputation: 27
I need to read my user Id to know what the timestart number is but I don't find the way to read the data.
//My code
const fs = require('fs');
var timePath = 'test.json'
var TimeRead = fs.readFileSync(timePath);
var timeFile = JSON.parse(TimeRead); //ready for use
var userId = "2"
var Time = TimeRead.userId.TimeStart;
console.log(Time)
1 is my user Id variable
//My json File
{
"1": {
"TimeStart": 1626909816680
},
"2": {
"TimeStart": 1627166305644
}
}
Upvotes: 0
Views: 89
Reputation: 11382
var Time = TimeRead.userId.TimeStart;
You can't use a variable with .
Try this:
var Time = TimeRead[userId].TimeStart;
Upvotes: 1