Hey there,
I've encountered a problem that I need help with: I have an object containing keys and values, and I want to create a new array of objects using this data. Below is the code snippet illustrating my issue.
const sourceObj = {
test1: "a",
test2: "b",
test3: "c",
test4: "d",
test5: "e"
};
const myTable = [];
for (let value of sourceObj) {
for (let i = 1; i < 6; i++) {
const targetObject = {
foo: "foo",
year: value.test + i,
bar: "bar"
};
myTable.push(targetObject);
}
}
console.log(myTable);
// expected output
// [
// {
// foo: "foo",
// year: "a",
// bar: "bar"
// },
// {
// foo: "foo",
// year: "b",
// bar: "bar"
// },
// ...
// {
// foo: "foo",
// year: "e",
// bar: "bar"
// },
// ]