Skip to content

Commit 453e485

Browse files
author
Walle Cyril
committed
Objects and Sets
1 parent 417ab20 commit 453e485

2 files changed

Lines changed: 48 additions & 8 deletions

File tree

js/Object.js

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,52 @@
1-
/*Knowledge about Object*/
1+
/* Knowledge about Object */
22
"use strict";
3-
/*How to create an empty Object ?*/
3+
4+
/* How to create an empty Object ? */
45
let anObject;
56

6-
// same
7+
// same
78
anObject = Object.create(Object);
9+
anObject = Object();
810
anObject = {};
911

1012
// without prototype
11-
anObject = Object.create(null);
13+
anObject = Object.create(null);
14+
15+
// assign simple
16+
anObject["key"] = "value";
17+
18+
// assign multiple
19+
Object.assing(anObject, {
20+
"key1": "value1",
21+
"key2": "value2",
22+
});
23+
24+
// get a specific value
25+
anObject["key"];
26+
27+
// get Length
28+
Object.keys(anObject).length;
29+
Object.values(anObject).length;
30+
Object.entries(anObject).length;
31+
32+
// iterate over
33+
// keys only
34+
Object.keys(anObject).forEach(function (key) {
35+
36+
});
37+
38+
// values only
39+
Object.values(anObject).forEach(function (value) {
40+
41+
});
42+
43+
// keys and values
44+
Object.entries(anObject).forEach(function ([key, value]) {
45+
46+
});
47+
48+
// has
49+
anObject.hasOwnProperty("key");
50+
51+
// has safe, works even when anObject has a key "hasOwnProperty"
52+
Object.prototype.hasOwnProperty.call(anObject, "key");

js/Set.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ s.add(6);
2424
s.add(7);
2525

2626
let l = listFromSet(s);
27-
let l2 = listFromSet2(s);
28-
let l3 = listFromSet3(s);
29-
30-
console.log(s, l, l2, l3);
27+
let l2 = listFromSet2(s);
28+
let l3 = listFromSet3(s);
29+
let l4 = [...s];

0 commit comments

Comments
 (0)