const object1 = {
a: 'somestring',
b: 42,
c: false
};
console.log(Object.keys(object1));
// expected output: Array ["a", "b", "c"]
var myObj = {no:'u',my:'sql'}
var keys = Object.keys(myObj);//returnes the array ['no','my'];
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"}
// }