1const object1 = {
2 a: 'somestring',
3 b: 42,
4 c: false
5};
6
7console.log(Object.keys(object1));
8// expected output: Array ["a", "b", "c"]
1var myObj = {no:'u',my:'sql'}
2var keys = Object.keys(myObj);//returnes the array ['no','my'];
1var users = [{userId: "1", name: 'harald'}, {userId: "2", name: 'jamie'}];
2var obj = {};
3users.forEach(user => {
4 obj = {
5 ...obj,
6 [user.userId]: user,
7 }
8})
9console.log(obj)
10// {
11// 1: {userId: "1", name: "harald"}
12// 2: {userId: "2", name: "jamie"}
13// }