In Javascript, how to map and convert this object:
{
0: {k1 : v1},
2: {k2 : v2}
}
to this array:
[
{
label: k1,
value: v1
},
{
label: k2,
value: v2
}
]
obs.: one-liners are nice, but all answers are welcome.
I couldn't get the desired result, but I have blindly followed formulas like:
const objectMap = (obj, fn) =>
Object.fromEntries(
Object.entries(obj).map(
([k, v], i) => [i, fn(v, k, i)]
)
)
const cfieldsFinal = objectMap(modcf, (k, v) => ({
label: v,
value: k
}))
and that's ALMOST what I need, except, it's still an object:
output => {0: {label: k1, value: v1}, 1: {label: k2, value: v2}}
So, only a complete noob such as myself would get stuck on this part...