Dynamic Properties
Short demonstration on how to add dynamic properties to a JavaScript object.
var data = {
'PropertyA': 1,
'PropertyB': 2,
'PropertyC': 3
};
data["PropertyD"] = 4;
// dialog box with 4 in it
alert(data.PropertyD);
alert(data["PropertyD"]);
I used this for an Exercism.io problem: “ETL” :
export const transform = (oldData) => {
let newData = new Object()
for (let [key, value] of Object.entries(oldData)) {
value.forEach(element => {
newData[element.toLowerCase()] = parseInt(key);
});
}
return newData;
};
REF: Exercism.io “ETL”, solution