-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproperties.js
32 lines (27 loc) · 860 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
var shoppingCart = {
books: 3,
sunglass: 1,
keyboard: 5,
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 propertyValue = shoppingCart[propertyName]
// console.log(propertyName, propertyValue);
var properties = Object.keys(shoppingCart);
var propertyValues = Object.values(shoppingCart);
// console.log(properties);
// console.log(propertyValues);
console.log(shoppingCart);
// set property values
shoppingCart.mouse = 15;
console.log(shoppingCart);
shoppingCart['mouse'] = 29;
console.log(shoppingCart);
shoppingCart[propertyName] = 89;
console.log(shoppingCart)