How do I run the data in the dictionary?
input:
const items = {
34: ["a", "t"],
43: ["d", "u"],
};
output:
run({34: "a"}),
run({34: "t"}),
run({43: "d"}),
run({43: "u"}),
Tried this:
[{ [Object.keys(items)[0]]: items[Object.keys(items)[0]] }]
but the output isn’t quite what I wanted.
>Solution :
- Iterate the entries then iterate the value array.
- Construct an object from the entry key and the array value and pass it to
run()
const items = {
34: ["a", "t"],
43: ["d", "u"],
};
// for demonstration purposes
const run = (arg) => console.log("run:", JSON.stringify(arg));
Object.entries(items).forEach(([ key, arr ]) => {
arr.forEach((val) => {
run({ [key]: val });
});
});
.as-console-wrapper { max-height: 100% !important; }