i am stumbling onto something that should be easy, yet i can't seem to be able to do it.
i have an array of string, and i want to map over it to create an object like so :
const monthesList = ['january', 'february', 'march', 'april', 'may']
const myState = monthesList.map(month => (
month: {selected: false, year: 2022}
)
)
what i want is to get the following object :
myState ={
january:{
selected: false,
year: 2022
},
february:{
selected: false,
year: 2022
},
march:{
selected: false,
year: 2022
},
april:{
selected: false,
year: 2022
},
may:{
selected: false,
year: 2022
},
}
Edit: i just found the way :
const myState = monthesList.map(month => (
{[month] : {
selected: false,
year: 2022
}}
)
)
just need to make an object out of it, shouldn't be too hard