Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

demonz's avatar

add array to the object in javascript

hello I have this code

let days = [2,3,4]
let hours = 4
I want to create an object to link the hours to each day
const workingDays = {
2:4,
3:4,
4:4,
}

I tried array.map inside the workinDays I guess it doesn't work that way

0 likes
1 reply
tykus's avatar

Not entirely sure if you're trying to generate the workingDays value, or something else???

Object.fromEntries(days.map(day => [day, 4]))

Please or to participate in this conversation.