1/// OBJECTS IN JAVASCRIPT
2const testScore = {
3 damon: 89,
4 shawn: 91,
5 keenan: 80,
6 kim: 89,
7};
8
9Object.keys(testScore); // gives all keys
10Object.values(testScore); // gives all values
11Object.entries(testScore); // gives nested arrays of key-value pairs
12
13// YOU CAN USE ( FOR-IN ) LOOP FOR ITERATION OVER OBJECTS
14for (let person in testScore) {...}
15
16// WE CAN'T DIRECTLY USE ( FOR-OF ) LOOP IN OBJECTS BUT WE CAN DO Like THIS:
17for(let score of Object.values(testScore)){
18 console.log(score) // 89 91 80 89
19}
20
21
1objectName.methodname = functionName;
2
3var myObj = {
4 myMethod: function(params) {
5 // ...do something
6 }
7
8 // OR THIS WORKS TOO
9
10 myOtherMethod(params) {
11 // ...do something else
12 }
13};
14