-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproperties.js
More file actions
39 lines (27 loc) · 874 Bytes
/
Copy pathproperties.js
File metadata and controls
39 lines (27 loc) · 874 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
var shoppingCart = {
books: 3,
sunglass: 5,
keyboard: 1,
mouse: 1,
pen: 25,
}
// when you know the specific property name , use dot notation to get the property value
var penCount = shoppingCart.pen;
/* alternative system */
// when you know the specific property name , use dot notation to get the property value
var penCount2 = shoppingCart['pen'];
var propertyName = 'mouse';
var propertyValues = shoppingCart[propertyName];
// console.log(propertyName, propertyValues);
var properties = Object.keys(shoppingCart);
var propertyValues = Object.values(shoppingCart);
// console.log(properties);
// console.log(propertyValues);
console.log(shoppingCart);
// set property value
shoppingCart.mouse = 15;
console.log(shoppingCart);
shoppingCart['mouse'] = 29
console.log(shoppingCart);
shoppingCart[propertyName] = 89;
console.log(shoppingCart);