-
Notifications
You must be signed in to change notification settings - Fork 0
/
properties.js
37 lines (28 loc) · 858 Bytes
/
properties.js
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
// 7(Object Properties/Keys and Values)
var shoppingCart = {
books: 3,
sunglass: 1,
keyboard: 5,
mouse: 1,
pen: 25
}
// 3 way to get object property value
// var penCount = shoppingCart.pen;
// console.log(penCount);
// var penCount2 = shoppingCart['pen'];
// console.log(penCount2);
var propertyName = 'mouse';
// var mouseValue = shoppingCart[propertyName];
// console.log(propertyName, mouseValue);
// Get object property and value by using JS reserve keywords
// var properties = Object.keys(shoppingCart);
// console.log(properties);
// var propertyValues = Object.values(shoppingCart);
// console.log(propertyValues);
// 3 way to change/set property values
shoppingCart.mouse = 15;
console.log(shoppingCart);
shoppingCart['mouse'] = 29;
console.log(shoppingCart);
shoppingCart[propertyName] = 89;
console.log(shoppingCart)