I'm trying to expand some Javascript code that creates JSON objects based on a input integer. The original integer spanned from 1 to 3 so the Javascript code used a single fixed piece of code for the JSON object creation. Here is the code and it's ouput:
function makeObject(stationNumber) {
if (stationNumber == 1) {
var obj = {
'station_1': [{
'totalEfficiency': 0,
'AvgTotalPass': 0,
'AvgTotalFail': 0,
'actualBulidTime': 0,
'idealBulidTime': 0,
'isWorking': 'true'
}]
}
console.log(obj)
return obj;
}
}
Output:
{ station_1:
[ { totalEfficiency: 0,
AvgTotalPass: 0,
AvgTotalFail: 0,
actualBulidTime: 0,
idealBulidTime: 0,
isWorking: 'true' } ] }
The station number is now expanding from a max of 3 to a max of 32 so I need to make the object creation use the input station number to create the object vs. the fixed code that was used. I've tried variations of this code:
var stationString = "string"
stationString = 'station_' + stationNumber.toString();
var obj = { stationString: [
{'totalEfficiency': 0, 'AvgTotalPass': 0,
'AvgTotalFail': 0, 'actualBulidTime': 0,
'idealBulidTime': 0,'isWorking': 'true'} ] }
Created Object:
{ stationString:
[ { totalEfficiency: 0,
AvgTotalPass: 0,
AvgTotalFail: 0,
actualBulidTime: 0,
idealBulidTime: 0,
isWorking: 'true' } ] }
Clearly the modification is not working correctly and searching for an answer that is similar to this has not been fruitful. I am very unfamiliar with Javascript(only "C" and Python) so any help would be appreciated.