I've this object called
const formValues = {...}
inside this object we have an array, this value must have one element or more,
formValues: {
locations: [...];
}
inside the array locations
we have multiple values: strings and objects.
formValues: {
locations: [
key1: string
key2: string
key3: object
key4: string
key5: object
key6: string
key7: object
];
}
How can i convert the key5
to an array ?
i already tried using the map
of lodash, but it doesn't work because at some point it generates a double array in the key5
( key5: [[...]]
)
const newFormValues = map(formValues, item =>
map(item, el => ({
...el,
workHours: [el.workHours],
})),
);
const data = {
data: { locations: flatten(newFormValues) },
section: 'locations',
confirm,
};
EXPECTED RESULT
The same object
formValues: {
locations: [
key1: string
key2: string
key3: object
key4: string
key5: **array**
key6: string
key7: object
];
}
but the key5 must be an array instead of an object