I want to combine two array object options in one field use select in reactJS. And this is my code:
const DayOptions = [
{
value: 'day1',
label: 'Day 1'
},
{
value: 'day 2',
label: 'Day 2'
},
etc...
];
const TimeOptions = [
{
value: '10:00AM',
label: '10:00 AM'
},
{
value: '10:30AM',
label: '10:30 AM'
},
etc...
];
const getDataList = () => {
const dataArr = []
DayOptions.map((item, index) => {
const newData = {
value: item.value,
label: item.label
}
dataArr.push(newData)
});
TimeOptions.map((item, index) => {
const newData = {
value: item.value,
label: item.label
}
dataArr.push(newData)
});
return dataArr;
};
return (
<Select
closeMenuOnSelect={true}
options={getDataList()}
/>
)
But, this code only works to select one array (only day or time) and does not combine two arrays (day and time) like the image below that I want. So what should i do? Thanks.