I have converted the string temp to Json string using json.stringify and then oarThe output of console.log(b_json.x) is coming undefined. ? This is my boys.json file
{
"b1":{
"attractiveness":"10",
"intelligence":"9",
"budget":"500",
"minAtt":"6",
"committed":"false",
"girlname":""
},
"b2":{
"attractiveness":"15",
"intelligence":"8",
"budget":"600",
"minAtt":"7",
"committed":"false",
"girlname":""
},
"b3":{
"attractiveness":"13",
"intelligence":"6",
"budget":"900",
"minAtt":"8",
"committed":"false",
"girlname":""
},
}
This is my boys.js file-
var b_json = require('./boys.json');
function utility() {
var arr_boys = new Array(3);;
for (var i = 1 ; i < arr_boys.length; i++) {
var temp = 'b'+i;
var t = JSON.stringify(temp);
var x = JSON.parse(t);
console.log(b_json.x);
}
}
utility()