til

Today I Learned: collection of notes, tips and tricks and stuff I learn from day to day working with computers and technology as an open source contributor and product manager

View project on GitHub

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

Resources and References