I am trying to create a dictionary from two separate lists with one list being the key and the other being the value.
I am currently using the code below to achieve this but it isn’t working.
const objects = columnNames.map((value) => {
const object: { [key: string]: any} = {};
standardNames.forEach((key, index) => {
object[key] = value[index];
});
return object;
});
The two lists I am trying to join together are:
const standardNames = ['Tests 1', 'Tests 2', 'Tests 3', 'Tests 4', 'Tests 5'];
const columnNames= ['Test 1', 'Test 2', 'Test 3', 'Test 4', 'Test 5'];
However what I get instead is:
[{"Tests 1":"T","Tests 2":"e","Tests 3":"s","Tests 4":"t","Tests 5":" "},{"Tests 1":"T","Tests 2":"e","Tests 3":"s","Tests 4":"t","Tests 5":" "},{"Tests 1":"T","Tests 2":"e","Tests 3":"s","Tests 4":"t","Tests 5":" "},{"Tests 1":"T","Tests 2":"e","Tests 3":"s","Tests 4":"t","Tests 5":" "},{"Tests 1":"T","Tests 2":"e","Tests 3":"s","Tests 4":"t","Tests 5":" "}]
2