var users = [{userId: "1", name: 'harald'}, {userId: "2", name: 'jamie'}];
var obj = {};
users.forEach(user => {
obj = {
...obj,
[user.userId]: user,
}
})
console.log(obj)
// {
// 1: {userId: "1", name: "harald"}
// 2: {userId: "2", name: "jamie"}
// }