I am trying to programmatically add properties to an object. This case is a little bit different though, and I am not sure how to approach this issue.
Normally, to apply properties to an object I would apply it in this context:
var a = []
var len = result[0].length
for(m=0; m < len; m++){
a[m] = "b" + m // creates b1-b17 usually, but if the results are shorter it will create them equal to the length of the results
}
const values = {}
for(g=0; g<len; g++){
values[a[g]] = [];
}
This would add an empty array to each property "b1" through "b17" normally, but its dynamic, in case the results are shorter.
Now I would like to do the same thing to this code, but inside the "return" part only. Is there anyway that I can call that and input those variables programmatically like I have done previously?
const rowData = tableData.map(result => {
for(var h in a){
values[a[h]].push(result[h]);
}
return {
//I want to put properties in here programmatically and dynamically like I did previously
}
})
Thank you guys for your time!
creates b1-b17 usuallyReally? It should create something likeb0-b17tableDataand show what you want the output to be.tableDatato be turned into an array ofb0..b17type values? Not at all clear what you're trying tro achieveconst values = {}; for(g = 0; g<len; g++) { values["b"+g] = []; }?