I have received an object that has the following structure:
{\"key1\":{\"cluster_region\":\"centralus\"},\"key2\":{\"cluster_region\":\"westeurope\"}}
My goal is to create a list of objects based on this given object. Each object in the list should contain two fields: "index" and "region". The "index" value should be the keys' values from the original object ("key1" and "key2"), while the region value should correspond to the "cluster_region" from the original object.
I attempted to achieve this using the following code:
const allrecords: Record<string, { cluster_region: string }> = initialObject;
console.log("all records: " + JSON.stringify(allrecords));
const allList = Object.entries(allrecords).map(([key, value]) => ({
index: key,
region: value.cluster_region
}));
Although I can see the correct value of allrecords
in the console log, which matches the initial object, the resulting list looks like this:
[{"index":"0"},{"index":"1"},{"index":"2"} ... ]
What am I doing incorrectly?