Skip to content

Commit f984132

Browse files
committed
Square Bracket Notation
1 parent 5dfdd9a commit f984132

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

challenges/09-array-methods.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,18 @@ const averageScore =
3636
}, 0) / students.length;
3737

3838
console.log(averageScore);
39+
40+
/* Example - Square Bracket Notation */
41+
const subject = 'physics';
42+
43+
const total = {};
44+
45+
// Static
46+
total.math = 3;
47+
total.history = 1;
48+
total.arts = 1;
49+
50+
// Dynamic Property Creation based on variable
51+
total[subject] = 'some value';
52+
53+
console.log(total);

0 commit comments

Comments
 (0)