This might not be the most popular question, but I'm asking for educational purposes...
Here is my current setup:
data = {COLUMN1: "DATA1", COLUMN2: "DATA2", COLUMN3: "DATA3", ..., COLUMNn: "DATAn"};
keyColumns = ["COLUMN2", "COLUMN5", "COLUMN9"];
keyValueMap = {};
This is what I am aiming to achieve:
keyValueMap = {COLUMN2: "DATA2", COLUMN5: "DATA5", COLUMN9: "DATA9"};
Here's what I have attempted so far:
if (keyColumns.length > 0)
{
keyColumns.forEach(key => {
keyValueMap[key] = data[key];
});
};
I understand that directly assigning values like keyvaluemap[a] = data[a] won't work since keyvaluemap is just an object. How can I structure this in a way that achieves my desired outcome of getting all value pairs? Also, keep in mind that the list of values in keyColumns is dynamic and cannot be predetermined.